首页 > 代码库 > Codeforces Round #415 (Div. 2)
Codeforces Round #415 (Div. 2)
Straight <<A>>
暴力模拟一下。
#include <iostream> #include <algorithm> #include <cmath> using namespace std; int main() { int n,k; cin>>n>>k; double sum = 0; for(int i=0;i<n;i++) { int x; cin>>x; sum += x; } double av = sum/n; int i = 0; for(;;) { if(round(av)==k) { cout<<i<<endl; break; } i++; sum += k; av = sum/(i+n); } return 0; }
Summer sell-off
按 min(ki*2,li)-ki 来从大到小来排序。
#include <iostream> #include <algorithm> #include <cmath> using namespace std; const int maxn = 1e5+5; typedef long long ll; struct block { ll k,l; ll d; ll diff; }; block e[maxn]; bool cmp(block A,block B) { return A.diff>B.diff; } int main() { int n,f; cin>>n>>f; for(int i=0;i<n;i++) { cin>>e[i].k>>e[i].l; e[i].d = e[i].k*2; e[i].diff = min(e[i].d,e[i].l)-e[i].k; } sort(e,e+n,cmp); ll sum = 0; int count1 = 0; for(int i=0;i<n;i++) { if(e[i].diff>0&&count1<f) { sum += min(e[i].d,e[i].l); count1++; } else { sum += min(e[i].k,e[i].l); } } cout<<sum<<endl; return 0; }
Do you want a date?
这个题稍微想了会。 想把所有数从大到小排一下。考虑每一个元素对于整体的贡献率,对于xi,它的贡献率是2^(n-i-1)-(2^i)。然后就是快速幂了。
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn = 3e5+5; typedef long long ll; const ll mod = 1e9+7; ll ans[maxn]; ll quick_pow(ll a,ll n) { ll res = 1; while(n) { if(n%2) res = res*a%mod; n /= 2; a = a*a%mod; } return res; } ll getsum(ll i,ll n,ll v) { ll a = quick_pow(2,n-i-1)%mod; ll b = quick_pow(2,i)%mod; ll sum = 0; if(n-i-1>=i) { sum = ((a+mod)-b)%mod; } else { sum = (a-b-mod)%mod; } return (sum*v)%mod; } bool cmp(ll A,ll B) { return A>B; } int main() { int n; cin>>n; ll sum = 0; for(int i=0;i<n;i++) { cin>>ans[i]; } sort(ans,ans+n,cmp); for(int i=0;i<n;i++) { sum = (sum + mod + getsum(i,n,ans[i]))%mod; } cout<<sum<<endl; return 0; }
Glad to see you!
Find a car
Codeforces Round #415 (Div. 2)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。