zoukankan      html  css  js  c++  java
  • Codeforces Round #401 (Div. 2)解题报告

    A - Shell Game

     1 #include <iostream>
     2 #include<bits/stdc++.h>
     3 #include <stack>
     4 #include <queue>
     5 #include <map>
     6 #include <set>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <math.h>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned long long ull;
    14 int n,x;
    15 int main()
    16 {
    17     scanf("%d %d",&n,&x);
    18     n%=6;
    19     if(x==0)
    20     {
    21         if(n==0||n==5)
    22         {
    23             printf("0
    ");
    24             return 0;
    25         }
    26         else if(n==1||n==2)
    27         {
    28             printf("1
    ");return 0;
    29         }
    30         else
    31         {printf("2
    ");return 0;}
    32 
    33     }
    34     else if(x==1)
    35     {
    36         if(n==0||n==3)
    37         {
    38             printf("1
    ");return 0;
    39         }
    40         else if(n==1||n==4)
    41         {
    42             printf("0
    ");return 0;
    43         }
    44         else if(n==2||n==5)
    45         {
    46             printf("2
    ");
    47             return 0;
    48         }
    49     }
    50     else if(x==2)
    51     {
    52         if(n==0||n==1)
    53         {
    54             printf("2
    ");return 0;
    55         }
    56         else if(n==2||n==3)
    57         {
    58             printf("0
    ");return 0;
    59         }
    60         else
    61         {
    62             printf("1
    ");return 0;
    63         }
    64     }
    65 }
    View Code

    B - Game of Credit Cards

     1 #include <iostream>
     2 #include<bits/stdc++.h>
     3 #include <stack>
     4 #include <queue>
     5 #include <map>
     6 #include <set>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <math.h>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned long long ull;
    14 char x[1005],y[1005];
    15 int  a[15],b[15];
    16 int n;
    17 int main()
    18 {
    19     scanf("%d",&n);
    20     scanf("%s",x);
    21     scanf("%s",y);
    22     int i;
    23     for(i=0;i<n;i++)
    24     {
    25         a[x[i]-'0']++;
    26         b[y[i]-'0']++;
    27     }
    28     int cnt1=0,cnt2=0;
    29     int he=0;
    30     for(i=9;i>=0;i--)
    31     {
    32         he+=b[i];
    33         he-=a[i];
    34         if(he<0)
    35         {
    36             cnt1+=abs(he);
    37             he=0;
    38         }
    39     }
    40     he=0;
    41     for(i=0;i<=8;i++)
    42     {
    43         he+=a[i];
    44 //        if(i>0)
    45 //        {
    46             cnt2+=min(he,b[i+1]);
    47             he-=min(he,b[i+1]);
    48 //        }
    49     }
    50     printf("%d
    %d
    ",cnt1,cnt2);
    51 }
    View Code

    C - Alyona and Spreadsheet

    数组储存每列情况,每次全for循环看就会TLE

     1 #include <iostream>
     2 #include<bits/stdc++.h>
     3 #include <stack>
     4 #include <queue>
     5 #include <map>
     6 #include <set>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <math.h>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned long long ull;
    14 const int MAX=1e5+5;
    15 vector <int> a[MAX],dp[MAX];
    16 int n,m;
    17 int len[MAX];
    18 int main()
    19 {
    20     scanf("%d %d",&n,&m);
    21     int i,j;
    22     for(i=1;i<=n;i++)
    23     {
    24         a[i].resize(m+1);
    25         for(j=1;j<=m;j++)
    26         scanf("%d",&a[i][j]);
    27     }
    28     for(i=1;i<=n;i++)
    29     {
    30         dp[i].resize(m+1,1);
    31         if(i-1)
    32         for(j=1;j<=m;j++)
    33             dp[i][j]+=((a[i][j]>=a[i-1][j])?dp[i-1][j]:0);
    34         for(j=1;j<=m;j++)
    35             len[i]=max(len[i],dp[i][j]);
    36     }
    37     int k;
    38     scanf("%d",&k);
    39     int l,r;
    40     while(k--)
    41     {
    42         scanf("%d %d",&l,&r);
    43         if(len[r]>=r-l+1)
    44             printf("Yes
    ");
    45         else
    46             printf("No
    ");
    47     }
    48 
    49 }
    View Code

    D - Cloud of Hashtags

     1 #include <iostream>
     2 #include<bits/stdc++.h>
     3 #include <stack>
     4 #include <queue>
     5 #include <map>
     6 #include <set>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <math.h>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned long long ull;
    14 const int MAXN=500005;
    15 string str[MAXN];
    16 void solve(int l,int r,int d)
    17 {
    18     for(int i=l;i<=r;i++)
    19     {
    20         if(i==l)
    21         {
    22             if((int)str[i].size()==d)l++;
    23             continue;
    24         }
    25         if((int)str[i].size()==d || str[i][d]<str[i-1][d])
    26         {
    27             for(int j=l;j<i;j++)
    28                 while((int)str[j].size()>d)str[j].pop_back();
    29             l=i--;
    30         }
    31     }
    32     for(int i=l,j=l;i<=r;i=j)
    33     {
    34         while(j<=r && str[j][d]==str[i][d])j++;
    35         solve(i,j-1,d+1);
    36     }
    37 }
    38 int main()
    39 {
    40     ios::sync_with_stdio(false);
    41     cin.tie(NULL);
    42     int n;
    43     cin>>n;
    44     for(int i=1;i<=n;i++)
    45         cin>>str[i];
    46     solve(1,n,0);
    47     for(int i=1;i<=n;i++)
    48         cout<<str[i]<<"
    ";
    49     return 0;
    50 }
    View Code

    解法2:string数组储存数据,设数组名称为x 用函数二分寻找满足 xi<=xi+1 的最大xi即可

     1 #include <iostream>
     2 #include<bits/stdc++.h>
     3 #include <stack>
     4 #include <queue>
     5 #include <map>
     6 #include <set>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <math.h>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned long long ull;
    14 const int MAX=5e5+5;
    15 string x[MAX];
    16 void change(string &a,string &b)//将a改变为小于b的最大字符串
    17 {
    18     int l,r,mid;
    19     string tmp;
    20     int an=0;
    21     l=1;
    22     r=a.size();
    23     while(l<=r)
    24     {
    25         mid=(l+r)/2;
    26         tmp=a.substr(0,mid);
    27         if(tmp<=b)
    28         {
    29             l=mid+1;
    30             an=mid;
    31         }
    32         else
    33             r=mid-1;
    34     }
    35     a=a.substr(0,an);
    36 
    37 }
    38 int main()
    39 {
    40     int n;
    41     int i;
    42     cin>>n;
    43     for(i=1;i<=n;i++)
    44         cin>>x[i];
    45     for(i=n-1;i>0;i--)
    46         change(x[i],x[i+1]);
    47     for(i=1;i<=n;i++)
    48         cout<<x[i]<<"
    ";
    49 }
    View Code

    明天一早坐飞机,具体分析明天补上。


    2.27upd:题目已经忘了太多,分析就不补上了……

  • 相关阅读:
    zepto源码解读(二)——zpeto.init()——(4)$.each()函数 / likeArray函数
    zepto源码解读(二)——zpeto.init()——(3)isFunction函数
    JS小问题之—— 关于SetCapture() 和 ReleaseCapture()的用法
    zepto源码解读(二)——zpeto.init()函数——(2)zepto.fragment()函数详解
    zepto源码解读(二)——zpeto.init()函数——(1)结构整理
    JS小问题之——缓冲运动
    zepto源码解读(一)——整体架构
    jquery源码猜想(一)
    去除小括号和小括号里面的内容
    查看端口使用情况
  • 原文地址:https://www.cnblogs.com/quintessence/p/6440483.html
Copyright © 2011-2022 走看看