Codeforces Round #169 (Div. 2)

A:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define NN 16384
#define INF 0x7ffffff
#define eps 1e-6
#define pi 3.14159265358979626

#define N 1005

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

    int n,k,Max;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        int v,f,t;
        scanf("%d%d",&f,&t);
        if (t>k) v=f-t+k;
        else v=f;

        if (i==1) Max=v;
        else if (v>Max) Max=v;
    }

    cout<

B:

统计不同的字母数,为0或1时先手赢。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define NN 16384
#define INF 0x7ffffff
#define eps 1e-6
#define pi 3.14159265358979626

#define N 1005

char s[N];
int num[30];

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

    gets(s);
    memset(num,0,sizeof(num));
    for (int i=0;i<(int)strlen(s);i++) num[ s[i]-'a'+1 ]++;

    int num1=0;
    for (int i=1;i<=26;i++) if ( (num[i]%2)!=0) num1++;

    if (num1==0) puts("First");
    else if (num1%2==0) puts("Second");
    else puts("First");

    return 0;
}
C :

线段树,插入线段,最后统计每个点出现次数。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define NN 16384
#define INF 0x7ffffff
#define eps 1e-6
#define pi 3.14159265358979626

#define N 262144

int n,q,a[N],ans1[N];
struct tree
{
    int c,b,e;
}p[2*N];

void build(int w,int a1,int a2)
{
    p[w].c=0;
    p[w].b=a1;
    p[w].e=a2;

    if (w=N || (s==p[w].b && t==p[w].e) )
    {
        p[w].c++;
        return ;
    }

    int mid=(p[w].b+p[w].e)/2;
    if (t<=mid) inse(2*w,s,t);
    else if (s>mid) inse(2*w+1,s,t);
    else
    {
        inse(2*w,s,mid);
        inse(2*w+1,mid+1,t);
    }
}

void cou(int h,int w,int ans)
{
    ans+=p[w].c;
    if (w>1) cou(h,w/2,ans);
    else ans1[h]=ans;
}

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

    build(1,1,N);
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);

    int s,t;
    for (int i=1;i<=q;i++)
    {
        scanf("%d%d",&s,&t);
        inse(1,s,t);
    }

    memset(ans1,0,sizeof(ans1));
    for (int i=1;i<=n;i++) cou(i,N+i-1,0);
    sort(ans1+1,ans1+n+1);

    long long ans=0;
    for (int i=1;i<=n;i++)
    ans+=(long long)ans1[i]*a[i];

    cout<

D:

找到b中第一个与a不同的二进制位,

设a>=b,找到第一位l与r不同的二进制位i,

那么必定是ai=1,bi=0.

那么a=1000000...

       b=0111111...

这样必定满足a<=r && b>=l && a>=b && a^b=max

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define NN 16384
#define INF 0x7ffffff
#define eps 1e-6
#define pi 3.14159265358979626
#define LL long long

#define N 262144

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

    LL a,b;
    cin>>a>>b;

    int c=0;
    LL a1;
    a1=a^b;
    while (a1>0)
    {
        c++;
        a1>>=(LL)1;
    }

    LL ans=0;
    for (int i=1;i<=c;i++) ans+=(LL)1<<(i-1);
    cout<


你可能感兴趣的:(Codeforces)