码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #415 (Div. 2)

时间:2017-05-26 23:24:56      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:off   模拟   car   wan   algorithm   opened   bre   closed   sort   

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;
}
Code

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;
}
Code

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;
}
Code

Glad to see you!

Find a car

Codeforces Round #415 (Div. 2)

标签:off   模拟   car   wan   algorithm   opened   bre   closed   sort   

原文地址:http://www.cnblogs.com/littlepear/p/6910662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!