Codeforces Round #334 (Div. 2) 题解

Uncowed Forces

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int main()
{
//  freopen("A.in","r",stdin);
//  freopen(".out","w",stdout);

    double m[10],w[10];
    For(i,5) cin>>m[i];
    For(i,5) cin>>w[i];
    double ans=0;

    For(i,5) ans+=max(0.3*i*500,(1-m[i]/(double)250)*i*500-50*w[i]);
    int a,b;
    cin>>a>>b;
    ans+=100*a-50*b;
    cout<<ans<<endl; 

    return 0;
}

More Cowbell

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
ll s[100000+10];
int n,k; 
bool check(ll m) {
     int t=0,l=1; 
     ForkD(i,l,n) {
        if (s[i]>=m) ++t;
        else {
            if (s[i]+s[l]<=m) l++;
            ++t;

        } 
     } 
     return t<=k; 
}
int main()
{
//  freopen("B.in","r",stdin);
//  freopen(".out","w",stdout);

    cin>>n>>k;
    ll tot=0;
    For(i,n) cin>>s[i],tot+=s[i];

    ll l=s[n],r=tot,ans=tot;
    while (l<=r) {
        ll m=(l+r)/2;
        if (check(m)) ans=m,r=m-1;
        else l=m+1; 
    }
    cout<<ans<<endl;


    return 0;
}

Alternative Thinking

翻的端点最好在2个相同数字之间

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
char s[3000000];
int main()
{
//  freopen("C.in","r",stdin);
//  freopen(".out","w",stdout);

    int n;
    cin>>n;
    scanf("%s",s+1);
    int t=1,p=0;
    Fork(i,2,n) {
        if (s[i]==s[i-1]) ++p;
        else ++t; 
    }
    if (p==1) t++;
    if (p>=2) t+=2;
    cout<<t<<endl; 

    return 0;
}

Moodular Arithmetic

一个f(x)可以确定好几个f(x),检查独立元个数

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define MAXN (10000000) 
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
class bingchaji
{
public:
    int father[MAXN],n;
    void mem(int _n)
    {
        n=_n;
        memset(father,-1,sizeof(father));
    }
    int getfather(int x) 
    {
        if (father[x]==-1) return x;
        return father[x]=getfather(father[x]);
    }
    void unite(int x,int y)
    {
        father[getfather(x)]=getfather(y);
    }
    bool same(int x,int y)
    {
        return getfather(x)==getfather(y);
    }
}S;

class Math
{
public: 
    ll pow2(ll a,int b,ll p)  //a^b mod p 
    {  
        if (b==0) return 1;  
        if (b==1) return a;  
        ll c=pow2(a,b/2,p);  
        c=c*c%p;  
        if (b&1) c=c*a%p;  
        return c;  
    }  

}S2;

int main()
{
//  freopen("D.in","r",stdin);
//  freopen(".out","w",stdout);

    ll p,k;
    cin>>p>>k;
    if (k==0) {
        cout<<S2.pow2(p,p-1,F);
    } else if (k==1) {
        cout<<S2.pow2(p,p,F);
    }
    else {
        S.mem((int)(p+10));
        For(i,p-1) {
            int t=(ll)i*(ll)k%p;
            if (!S.same(t,i))
                S.unite(t,i); 
        } 
        ll ans=1;
        For(i,p-1) {
            if (S.getfather(i)==i) {
                ans=mul(ans,p);
            } 
        }
        cout<<ans;


    }
    cout<<endl;
    return 0;
}

Lieges of Legendre

算sg函数找规律,记得k偶数时1,2的情况

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
#define MAXN (1000000+19) 
ll a[MAXN];
int n,k;
map<ll,int> h;
int sg(ll x) {
    if (x==0) return 0;
    if (h.count(x)) return h[x];
    int p1=sg(x-1),p2=-1;
    if (x%2==0) p2=sg(x/2);
    int c=0;
    while (c==p1||c==p2) ++c;
    h[x]=c;
    return c;   
}
int sg3(ll x) {
    if (x==0) return 0;
    int p1=sg3(x-1),p2=-1;
    if (x%2==0) p2=0;
    int c=0;
    while (c==p1||c==p2) ++c;
    return c;   
}
int sg2(ll x) {
    int t=0;
    if (x==2) return 0; 
    if (x==1 || x==3 ) t^=1;
    else if (x&1) return 0;
    else {
        int k=0;
        while (x%2==0) x/=2,++k;
        if (x==3) {
            if (k&1) return 2;else return 1;  

        }
        if (k&1) return 1;else return 2;  
    } 
    return t;
}

int main()
{
//  freopen("E.in","r",stdin);
//  freopen(".out","w",stdout);

//  k=1;
    cin>>n>>k;
    For(i,n) cin>>a[i];

//  For(i,100) cout<<sg3(i)<<' ';


    int t=0;

    if (k%2==0) {
        For(i,n) {
            if (a[i]==1) t^=1; 
            else if (a[i]==2) t^=2;  
            else if (a[i]%2==0) t^=1; 

        }
    } else {
        For(i,n) t^=sg2(a[i]);  
    }
    if (t) cout<<"Kevin";else cout<<"Nicky";cout<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值