zoukankan      html  css  js  c++  java
  • Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2)

    codeforces 876 A. Trip For Meal(水题)

    题意:R、O、E三点互连,给出任意两点间距离,你在R点,每次只能去相邻点,要走过n个点,求走过的最短距离。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int main() {
     6     int n, a, b, c;
     7     scanf("%d%d%d%d", &n, &a, &b, &c);
     8     if(n==1) puts("0");
     9     else printf("%d
    ", (n-2) * min(a, min(b,c)) + min(a,b));
    10     return 0;
    11 }
    30ms

    codeforces 876 B. Divisiblity of Differences(水题)

    题意:有N个数,要从中选出K个,要求选出的数相减后都能整除m,求能都选出K个数,并输出选出的数。

    题解:容易发现选出的数一定是 对m取余相同 的一类数,将每类数存起来,大于K个则输出这一类。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<vector>
     5 using namespace std;
     6 typedef long long ll;
     7 const int N = 100005;
     8 int a[N];
     9 vector<int>c[N];
    10 int main() {
    11     int n, k, m, i, j, f = 0;
    12     for(i = 0; i < N; ++i) c[i].clear();
    13     scanf("%d%d%d", &n, &k, &m);
    14     for(i = 1; i <= n; ++i) {
    15         scanf("%d", &a[i]);
    16         c[a[i]%m].push_back(i);
    17     }
    18     for(i = 0; i < m; ++i) {
    19         if(c[i].size() >= k) {
    20             puts("Yes");    f = 1;
    21             for(j = 0; j < k-1; ++j) printf("%d ", a[c[i][j]]);
    22             printf("%d
    ", a[c[i][k-1]]);
    23             break;
    24         }
    25     }
    26     if(!f) puts("No");
    27     return 0;
    28 }
    61ms

    codeforces 875 A. Classroom Watch(暴力)

    题意:给你n要求有几个x满足 x加上x的各个数位之和等于n,比如:x=100a+10b+c,n=x+a+b+c。

    题解:暴力,枚举i(各个数位之和),令x=n-i再检验x是否满足题意。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int a[105];
     6 int main() {
     7     int n, i, j, x, y, cnt = 0;
     8     scanf("%d", &n);
     9     for(i = min(n-1,100); i >= 1; --i) {
    10         x = n - i;  y = 0;
    11         while(x) {y += x%10; x /= 10;}
    12         if(y == i) a[cnt++] = n-i;
    13     }
    14     printf("%d
    ", cnt);
    15     for(i = 0; i < cnt; ++i) printf("%d
    ", a[i]);
    16     return 0;
    17 }
    15ms

    codeforces 875 B. Sorting the Coins(模拟)

    题意:一排n个位置,每次操作在p[i]位置放硬币,从左往右看,如果第i个位置有硬币,第i+1位置没有,则交换硬币(可以看看题目Note就好懂了,X0X0->0X0X是换了两次硬币,但这是一步,从左往右看一次是一步),直到无法再交换位置,求每次操作要几步。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 const int N = 300005;
     6 int a[N];
     7 int main() {
     8     int n, i, x;
     9     scanf("%d", &n);
    10     int m = n + 1;
    11     printf("1");
    12     for(i = 1; i <= n; ++i) {
    13         scanf("%d", &x);
    14         a[x] = 1;
    15         while(a[m-1]) m--;
    16         printf(" %d", i-n+m);
    17     }
    18     return 0;
    19 }
    155ms

    不补题了,看不透英语。。。

  • 相关阅读:
    整数反转
    最长公共前缀
    罗马数字转整数
    单点登录
    VMware Workstation虚拟机密钥
    Pytest 用例内部执行顺序
    判断是不是回文数
    python端口IP字符串是否合法
    python求二叉树深度
    有两个字符串类型的数字,实现一个方法将它们进行相加,并返回相加后的数值。
  • 原文地址:https://www.cnblogs.com/GraceSkyer/p/7679563.html
Copyright © 2011-2022 走看看