Codeforces Round #531 (Div. 3)

http://codeforces.com/contest/1102

今早上打的虚拟场。这次的div3比上次友好,但还是想写博客。昨晚是上分场,貌似错过了什么。

A:找规律即可。11001100.

B:题意有点坑。WA了一发之后觉得题意不对,发现每一个颜色都要涂上。相同的号要涂不同的颜色,简单分下号就可以了。

#include
using namespace std;
typedef long long LL;
const int maxn=1000000;
int a[6000];
int v[6000][6000];
mapmp;
int main()
{
   int n,k,x;
   int maxx=0;
   while(scanf("%d%d",&n,&k)!=EOF){
        mp.clear();
        memset(v,0,sizeof(v));
        maxx=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mp[a[i]]++;
            maxx=max(maxx,mp[a[i]]);
        }
        if(maxx>k)
            printf("NO\n");
        else{
            printf("YES\n");
            int xpp=1;
            for(int i=1;i<=n;i++){

             if(v[a[i]][xpp]==0)
             {

                 v[a[i]][xpp]=1;
                 cout<k)
                    xpp=1;
             }
             else{
                while(1){

                    xpp++;
                    if(xpp>k)
                        xpp=1;
                    if(v[a[i]][xpp]==0)
                    {
                        v[a[i]][xpp]=1;
                        cout<

C:比较一下X,Y的大小即可。

D:就是以替换为主。

先看0.缺0的话从左边开始替换。

再看2,缺2的话从右边开始替换

1的话有点特殊。先从右边找多的0.还缺的话再从左边找多的2.

#include
using namespace std;
typedef long long LL;
const int maxn=1000000;
int a[maxn];
int v[6000][6000];
mapmp;
int main()
{
    int n,yi,er,zero;
    string h;
    while(scanf("%d",&n)!=EOF){
        zero=0;yi=0;er=0;
        cin>>h;
        int len=h.size();
        for(int i=0;ixpp){
                        h[i]='0';
                        zero++;
                        yi--;
                    }
                }
                else if(h[i]=='2'){
                        if(er>xpp){
                            h[i]='0';
                            zero++;
                            er--;
                        }
                }
                if(zero>=xpp)
                    break;
            }
        }

        if(er=0;i--){
                if(h[i]=='0')
                {
                    if(zero>xpp){
                        er++;
                        zero--;
                        h[i]='2';
                    }
                }
                else if(h[i]=='1'){
                    if(yi>xpp){
                        er++;
                        yi--;
                        h[i]='2';
                    }
                }
            if(er>=xpp)
                    break;
            }
        }
        /*
        if(yi=0;i--){
                if(h[i]=='2')
                {
                    if(er>xpp){
                        yi++;
                        er--;
                        h[i]='1';
                    }
                }
                else if(h[i]=='0'){
                    if(zero>xpp){
                        yi++;
                        zero--;
                        h[i]='1';
                    }
                }
                if(yi>=xpp)
                    break;
            }
        }
*/
            if(yi=0;i--){
                if(h[i]=='0'){
                    if(zero>xpp){
                        yi++;
                        zero--;
                        h[i]='1';
                    }
                }
                if(yi>=xpp)
                    break;
            }
        }
        if(yixpp){
                        yi++;
                        er--;
                        h[i]='1';
                    }
                }
                if(yi>=xpp)
                    break;
            }
        }
        cout<

E:看有几大块。然后是2的n次方。

#include
using namespace std;
typedef long long LL;
const int maxn=1000000;
int a[maxn];
maplast;///记录i最后一次出现的位置
const LL mo=998244353;
LL power(LL a,LL n)   //a的n次方mod
{
    LL ans=1;
    a=a%mo;
    while (n)
    {
        if(n&1) ans=(ans*a)%mo;
        n>>=1;
        a=(a*a)%mo;
        }
    return ans;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            last[a[i]]=i;
        }
        int num=0;
        int maxx=0;
        for(int i=1;i<=n;i++){
             if(i>maxx)
                num++;
              maxx=max(maxx,last[a[i]]);///看最远到哪里
        }
        cout<

 

你可能感兴趣的:(比赛)