zoukankan      html  css  js  c++  java
  • Codeforces GoodBye2013 解题报告

    第一次能和div1的大神们一起比赛,甚是紧张。只做出来三题,先贴一下吧。

    Problem A New Year Candles

    题意:有若干新蜡烛,用完两个旧蜡烛就能造一个新蜡烛,每个蜡烛能燃烧1小时。问最多能燃烧多少个小时?

    思路:这道题直接爆,虽然有点傻但是比赛的时候保险。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <utility>
     7 #include <queue>
     8 #include <stack>
     9 #include <vector>
    10 #define ll long long
    11 #define INF 0x7fffffff
    12 #define eps 1E-6
    13 
    14 using namespace std;
    15 
    16 int main()
    17 {
    18 //    freopen("in.txt", "r", stdin);
    19     int a, b;
    20     while(scanf("%d%d", &a, &b)!=EOF){
    21         int cnt = 0, old = 0;
    22         while(a){
    23             cnt++;
    24             a--;
    25             old++;
    26             if(old == b){
    27                 a++;
    28                 old = 0;
    29             }
    30         }
    31         printf("%d
    ", cnt);
    32     }
    33     return 0;
    34 }
    View Code

    Problem B New Year Present

    题意:有若一个序列,然后地板上有一排空钱包。你需要的是操控一个机器人,最终是钱包中的值符合这个序列,机器人能执行三个操作L向左一格,R向右一格,P放一枚硬币。P操作不能连续执行两次。

    思路:标准的模拟题。让机器人来回走若是还有钱包没投满就继续走,每走到一个没满的钱包就投一个硬币,一边走一边输出序列。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <utility>
     7 #include <queue>
     8 #include <stack>
     9 #include <vector>
    10 #define ll long long
    11 #define INF 0x7fffffff
    12 #define eps 1E-6
    13 #define LEN 1000100
    14 
    15 using namespace std;
    16 
    17 int n, a[LEN];
    18 
    19 int main()
    20 {
    21 //    freopen("in.txt", "r", stdin);
    22 
    23     while(scanf("%d", &n)!=EOF){
    24         ll sum = 0;
    25         for(int i=0; i<n; i++){
    26             scanf("%d", &a[i]);
    27             sum += a[i];
    28         }
    29         for(int cc = 0; sum; cc++){
    30             for(int i=0; i<n; i++){
    31                 if(cc!=0 && i==0)continue;
    32                 if(a[i]){
    33                     printf("P");
    34                     a[i]--;
    35                     sum--;
    36                     if(sum==0)goto A;
    37                 }
    38                 if(i!=n-1)printf("R");
    39                 else printf("L");
    40             }
    41             for(int i=n-2; i>=0; i--){
    42                 if(a[i]){
    43                     printf("P");
    44                     a[i]--;
    45                     sum--;
    46                     if(sum==0)goto A;
    47                 }
    48                 if(i!=0)printf("L");
    49                 else printf("R");
    50             }
    51         }
    52         A:printf("
    ");
    53     }
    54     return 0;
    55 }
    View Code

    Problem C New Year Ratings Change

    题意:有若干个人每个人有不同的需求,然后你分配满足这些人的需求,但是没有两个人的分配的会是相同。最后输出每一个分配的实际值。

    思路:读进来每个人标记(序号,需求,实际分配)首先按照需求排序,在设计一个loc表示当前分配到的最低值。每次判断若是需求小于loc则直接分配。否则loc赋值为需求。最后按照序号排序输出。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <utility>
     7 #include <queue>
     8 #include <stack>
     9 #include <vector>
    10 #define ll long long
    11 #define INF 0x7fffffff
    12 #define eps 1E-6
    13 #define LEN 1000100
    14 
    15 using namespace std;
    16 
    17 typedef struct {
    18     int x, rat, get;
    19 }P;
    20 P s[LEN];
    21 int n;
    22 
    23 bool cmp1(P a, P b){return a.rat<b.rat;}
    24 bool cmp2(P a, P b){return a.x<b.x;}
    25 
    26 int main()
    27 {
    28 //    freopen("in.txt", "r", stdin);
    29 
    30     while(scanf("%d", &n)!=EOF){
    31         for(int i=0; i<n; i++){
    32             s[i].x = i;
    33             scanf("%d", &s[i].rat);
    34         }
    35         sort(s, s+n, cmp1);
    36         int loc = s[0].rat;
    37         s[0].get = loc;
    38         for(int i=1; i<n; i++){
    39             if(s[i].rat <= loc){
    40                 loc++;
    41             }else{
    42                 loc = s[i].rat;
    43             }
    44             s[i].get = loc;
    45         }
    46         sort(s, s+n, cmp2);
    47         for(int i=0; i<n; i++){
    48             printf("%d", s[i].get);
    49             if(i!=n-1)printf(" ");
    50         }
    51         printf("
    ");
    52     }
    53     return 0;
    54 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    Seafile开源私有云自定义首页Logo图片
    启动seafile报错Error happened during creating seafile admin.
    jupyter的安装和使用(python3版)
    C#学习资料
    服务编排-以docker-swarm为例讲解
    docker swarm架构图
    VMware中安装centos7
    js获取数据:类似xpath
    博客园备份python程序
    解决docker中jenkins运行磁盘满的问题
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3498704.html
Copyright © 2011-2022 走看看