zoukankan      html  css  js  c++  java
  • Codeforces Round #427 (Div. 2)

    A题

    分析:按题意比较二者之间的大小关系即可

     1 #include "iostream"
     2 #include "cstdio"
     3 #include "cstring"
     4 using namespace std;
     5 int s,v1,v2,t1,t2;
     6 int main()
     7 {
     8     cin>>s>>v1>>v2>>t1>>t2;
     9     int num1=2*t1+s*v1;
    10     int num2=2*t2+s*v2;
    11     if(num1<num2)
    12         cout<<"First"<<endl;
    13     else if(num1>num2)
    14         cout<<"Second"<<endl;
    15     else
    16         cout<<"Friendship"<<endl;
    17     return 0;
    18 }
    View Code

    B题

    分析:按照从小打到排序,然后每个位置变到9就能求出最少的变化了

     1 #include "iostream"
     2 #include "cstdio"
     3 #include "cstring"
     4 #include "string"
     5 #include "algorithm"
     6 using namespace std;
     7 const int maxn=100000+100;
     8 char s[maxn];
     9 int k;
    10 int main()
    11 {
    12     scanf("%d",&k);
    13     getchar();
    14     char ch=getchar();
    15     int n=0;
    16     while(ch!='
    ')  s[++n]=ch,ch=getchar();
    17     sort(s+1,s+n+1);
    18     int num=0;
    19     for(int i=1;i<=n;i++)
    20         num+=(s[i]-'0');
    21     int res=k-num;
    22     int i=1;
    23     int cnt=0;
    24     while(res>0){
    25         if(s[i]=='9'){
    26             i++;
    27         }else{
    28             int cha='9'-s[i];
    29             res-=cha;
    30             cnt++;
    31             i++;
    32         }
    33     }
    34     cout<<cnt<<endl;
    35 }
    View Code

    C题

    分析:首先我们统计出每个位置,每个值的个数,然后维护一个前缀和,就可以知道区间当中的值

     1 #include "iostream"
     2 #include "cstdio"
     3 #include "cstring"
     4 #include "string"
     5 using namespace std;
     6 const int maxn=100+10;
     7 int vis[15][maxn][maxn];
     8 int num[15][maxn][maxn];
     9 int n,q,c;
    10 int main()
    11 {
    12     scanf("%d%d%d",&n,&q,&c); ++c;
    13     for(int i=1;i<=n;i++){
    14         int x,y,r;
    15         scanf("%d%d%d",&x,&y,&r);
    16         vis[r][x][y]++;
    17     }
    18     for(int l=0;l<c;l++)
    19         for(int i=1;i<=100;i++)
    20             for(int j=1;j<=100;j++)
    21                 num[l][i][j]=num[l][i-1][j]+num[l][i][j-1]-num[l][i-1][j-1]+vis[l][i][j];
    22     while(q--){
    23         int t,x1,y1,x2,y2;
    24         scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);
    25         int cnt=0;
    26         for(int l=0;l<c;l++)
    27             cnt+=(num[l][x2][y2]-num[l][x1-1][y2]-num[l][x2][y1-1]+num[l][x1-1][y1-1])*((l+t)%c);
    28         printf("%d
    ",cnt);
    29     }
    30 }
    View Code
  • 相关阅读:
    606. Construct String from Binary Tree
    696. Count Binary Substrings
    POJ 3255 Roadblocks (次短路)
    POJ 2823 Sliding Window (单调队列)
    POJ 1704 Georgia and Bob (博弈)
    UVa 1663 Purifying Machine (二分匹配)
    UVa 10801 Lift Hopping (Dijkstra)
    POJ 3281 Dining (网络流之最大流)
    UVa 11100 The Trip, 2007 (题意+贪心)
    UVaLive 4254 Processor (二分+优先队列)
  • 原文地址:https://www.cnblogs.com/wolf940509/p/7269135.html
Copyright © 2011-2022 走看看