• Codeforce Round #553(Div2)


    开的虚拟赛,做了ABCD,写一下BCD吧:

      Bwa了三发.题意大概就是有一个n*m矩阵,从每一行拿出一个数,使得这n个数异或和大于0.想了一下就开始写:只要判断一下是否有一行有两个不同的数,其他行都去第一个,不就ok了?第一发WA了以后发现有这种情况:3 3 2 2 4 4 6 6即一行中每一列都是一样的,但是行与行的数是不一样的,考虑了这种情况,改一下就过了(中间有一次WA是没有记录有两个不同数的行的行号....直接在最后输出了)

      代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,m;
     4 const int maxn=505;
     5 int mat[maxn][maxn];
     6 int store[2];
     7 int row;
     8 int main()
     9 {
    10     ios::sync_with_stdio(0);
    11     cin>>n>>m;
    12     for(int i=1;i<=n;++i)
    13     {
    14         for(int j=1;j<=m;++j)
    15         {
    16             cin>>mat[i][j];
    17             if(mat[i][j]!=mat[i][1])
    18             {
    19                 row=i;
    20                 store[0]=1;
    21                 store[1]=j;
    22             }
    23         }
    24     }
    25     if(store[0]==store[1] && store[1]==0)
    26     {
    27         int ans=0;
    28         for(int i=1;i<=n;++i) ans^=mat[i][1];
    29         if(ans)
    30         {
    31             cout<<"TAK"<<endl;
    32             for(int i=1;i<=n;++i) cout<<"1 ";
    33         }
    34         else
    35         {
    36             cout<<"NIE";
    37         }
    38         return 0;
    39     }
    40     else
    41     {
    42         cout<<"TAK"<<endl;
    43         int ans=0;
    44         for(int i=1;i<=n;++i) ans^=mat[i][1];
    45         if(ans>0) 
    46         {
    47             for(int i=1;i<=n;++i) cout<<"1 ";
    48             return 0;
    49         }
    50         else
    51         {
    52             for(int i=1;i<=n;++i)
    53             {
    54                 if(i==row) cout<<store[1]<<" ";
    55                 else cout<<"1 ";
    56             }
    57         }
    58     }
    59     
    60 }

      C一开始没想到,因为对于一个位置c,我们可以确定1-c一共有多少个连续的奇数和偶数,然后用前缀和的思想搞一下就好......(太菜了,1700的题还是不能想到正确做法,一开始想到了一个巨麻烦的做法这里就不提了)

      代码:

      

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int mod=1e9+7;
    ll cal(ll x)
    {
        ll base;
        ll odd=0,even=0;
        ll i;
        for(i=0;i<63;++i)
        {
            if((1ll<<i+1)-1>=x)
            {
                base=(1ll<<i)-1;
                break;
            }
            if(i&1) even+=1ll<<i;
            else odd+=1ll<<i;
        }
    
        if(i&1) even+=x-base;
        else odd+=x-base;
        even%=mod,odd%=mod;//这里先取模一下再计算
        return (even*even+even+odd*odd)%mod;
    }
    int main()
    {
        ll l,r;cin>>l>>r;
        cout<<(cal(r)-cal(l-1)+mod)%mod;注意可能是负数的情况,加上一个mod再取模
    }

      D题贪心,排序一下就好

      

      代码:

      

     1 #include<bits/stdc++.h>
     2 #define pii pair<int,int>
     3 using namespace std;
     4 int n;
     5 int main()
     6 {
     7     ios::sync_with_stdio(0);
     8     vector<pii>v;
     9     cin>>n;
    10     for(int i=1;i<=n;++i)
    11     {
    12         int a,b;
    13         cin>>a>>b;
    14         v.push_back(make_pair(a,b));
    15     }
    16     sort(v.begin(),v.end(),[](pii a,pii b){
    17         return a.first-a.second>b.first-b.second;
    18         });
    19     long long ans=0;
    20     for(int i=1;i<=n;++i)
    21     {
    22         ans+=1ll*v[i-1].first*(i-1)+1ll*v[i-1].second*(n-i);
    23     }
    24     cout<<ans;
    25 }
  • 相关阅读:
    Swift
    Swift
    POJ2029——Get Many Persimmon Trees
    windows-install-python-and-sphinx(*.rst file)
    【cocos2d-x】尝鲜 Cocos Code IDE(不断更新)
    mysql 删除重复数据sql声明
    开销是有益的:AppCan 至HTML5移动创新和创业精神和健康
    hibernate它5.many2one单向
    Insecure default in Elasticsearch enables remote code execution
    TestNg显示器(一个)-----监听器,类型和配置使用---另外META-INF详细解释
  • 原文地址:https://www.cnblogs.com/codeoosacm/p/10805368.html
Copyright © 2020-2023  润新知