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

    Problem A George and Sleep

    题意:给出两个时间计算上面减下面。水题

    代码如下:

     1 //2014-01-30-21.18
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <cstring>
     7 #include <algorithm>
     8 #include <queue>
     9 #include <stack>
    10 #include <vector>
    11 #include <set>
    12 #include <map>
    13 #define MP(a, b) make_pair(a, b)
    14 #define PB(a) push_back(a)
    15 
    16 using namespace std;
    17 
    18 typedef long long ll;
    19 typedef pair<int ,int> pii;
    20 typedef pair<unsigned int, unsigned int> puu;
    21 typedef pair<int ,double> pid;
    22 typedef pair<ll, int> pli;
    23 typedef pair<int, ll> pil;
    24 
    25 const int INF = 0x3f3f3f3f;
    26 const double eps = 1e-6;
    27 
    28 int main()
    29 {
    30 //    freopen("in.txt", "r", stdin);
    31 
    32     int a, b, c, d;
    33     while(scanf("%d:%d", &a, &b)!=EOF){
    34         scanf("%d:%d", &c, &d);
    35         int f = b>=d?0:1;
    36         b = (b-d+60)%60;
    37         a = (a+24-f-c)%24;
    38         printf("%02d:%02d
    ", a, b);
    39 //        cout << a << ' ' << b << endl;
    40     }
    41     return 0;
    42 }
    View Code

    Problem B George and Round

    题意:George要准备一场比赛现在一有m个问题第i个难度为a[i],比赛至少有n个问题每个问题难度必须是b[i].george可以把一个难度大的问题降低。问你他最少需要新出几道题才能满足需要。

    思路:由于大的能变小的,所以贪心一下用a中最小的尝试匹配b中最小的。即可得出答案

    代码如下:

     1 //2014-01-30-21.18
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <cstring>
     7 #include <algorithm>
     8 #include <queue>
     9 #include <stack>
    10 #include <vector>
    11 #include <set>
    12 #include <map>
    13 #define MP(a, b) make_pair(a, b)
    14 #define PB(a) push_back(a)
    15 
    16 using namespace std;
    17 
    18 typedef long long ll;
    19 typedef pair<int ,int> pii;
    20 typedef pair<unsigned int, unsigned int> puu;
    21 typedef pair<int ,double> pid;
    22 typedef pair<ll, int> pli;
    23 typedef pair<int, ll> pil;
    24 
    25 const int INF = 0x3f3f3f3f;
    26 const double eps = 1e-6;
    27 const int LEN = 10010;
    28 
    29 int main()
    30 {
    31 //    freopen("in.txt", "r", stdin);
    32 
    33     int n, m, a[LEN], b[LEN];
    34     while(scanf("%d%d", &n, &m)!=EOF){
    35         for(int i=0; i<n; i++)scanf("%d", &a[i]);
    36         for(int i=0; i<m; i++)scanf("%d", &b[i]);
    37         sort(a, a+n);
    38         sort(b, b+m);
    39         int top = 0;
    40         for(int i=0; i<m; i++){
    41             if(b[i]>=a[top]){top++;if(top==n)break;}
    42         }
    43         printf("%d
    ", n-top);
    44     }
    45     return 0;
    46 }
    View Code

    Problem C George and Number

    题意:有一个数列b能执行一系列操作:

    每次选i,j满足b[i]>b[j]。

    v = concat(bi, bj),就是把大的数拼接在小的前面。

    将v加入末尾。

    删除b[i],b[j]

    最终得到一个数。现在告诉你这个数,问你原先数列最多可能有几个数。

    思路:仔细观察操作我们可以知道,只要满足每次把大数截断并且满足前面大于后面我们就能多造出来一个数并且对前面的那个数递归的解决问题。最终得到答案

    代码如下:

     1 //2014-01-30-21.18
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <cstring>
     7 #include <algorithm>
     8 #include <queue>
     9 #include <stack>
    10 #include <vector>
    11 #include <set>
    12 #include <map>
    13 #define MP(a, b) make_pair(a, b)
    14 #define PB(a) push_back(a)
    15 
    16 using namespace std;
    17 
    18 typedef long long ll;
    19 typedef pair<int ,int> pii;
    20 typedef pair<unsigned int, unsigned int> puu;
    21 typedef pair<int ,double> pid;
    22 typedef pair<ll, int> pli;
    23 typedef pair<int, ll> pil;
    24 
    25 const int INF = 0x3f3f3f3f;
    26 const double eps = 1e-6;
    27 const int LEN = 1000000+10;
    28 char str[LEN], a[LEN], b[LEN];
    29 
    30 //b是不是比a大
    31 bool isbig(int i, int l){
    32     int la = i, lb = l-i;
    33     if(la>lb) return true;
    34     else if(la<lb) return false;
    35     else{
    36         for(int pos=0; pos<la; pos++){
    37             if(str[pos] > str[i+pos]) return true;
    38             if(str[pos] < str[i+pos]) return false;
    39         }
    40         return true;
    41     }
    42 }
    43 
    44 int main()
    45 {
    46 //    freopen("in.txt", "r", stdin);
    47 
    48     while(scanf("%s", str)!=EOF){
    49         int i = strlen(str)-1, l = i+1, ans = 0;
    50         while(i>=0){
    51             if(str[i] != '0') {
    52                 if(isbig(i, l)){
    53                     ans++;
    54                     l = i;
    55                 }
    56             }
    57             i--;
    58         }
    59         printf("%d
    ", ans+1);
    60     }
    61     return 0;
    62 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    eval命令的使用
    declare与typeset的使用
    【线型DP模板】最上上升子序列(LIS),最长公共子序列(LCS),最长公共上升子序列(LCIS)
    【线型DP】【LCS】UVA_10635 Prince and Princess
    【经典DP】洛谷 P2782 友好城市
    HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)
    BZOJ3659 Which Dreamed It
    CF300D Painting Square
    CF632E Thief in a Shop 和 CF958F3 Lightsabers (hard)
    CF528D Fuzzy Search 和 BZOJ4259 残缺的字符串
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3536702.html
Copyright © 2011-2022 走看看