Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码

A题链接:https://codeforces.com/contest/1036/problem/A

A题AC代码:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include <malloc.h>
 6 #include <stdbool.h>
 7 #include <ctype.h>
 8
 9 typedef long long ll;
10
11
12 int main()
13 {
14     ll n, k, i, j, ans;
15     while( ~scanf( "%I64d%I64d", &n, &k ) )
16     {
17         printf( "%I64d\n", ( k + n - 1 ) / n );
18     }
19     return 0;
20 }

B题链接:https://codeforces.com/contest/1036/problem/B

B题AC代码:

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4
 5 typedef unsigned long long ULL;
 6 typedef const int cint;
 7 typedef long long LL;
 8 using namespace std;
 9
10
11 int q;
12 LL n,m,k;
13 template< typename Q >
14 void inin(Q &);
15
16 int main()
17 {
18     inin(q);
19     while( q -- )
20     {
21         inin(n);
22         inin(m);
23         inin(k);
24         if( n > m )
25             swap( n, m );
26         if( k < m )
27             printf( "-1" );
28         else
29         {
30             if( n == m )
31             {
32                 if( ( k-n ) & 1 )
33                     printf( "%I64d", k - 2 );
34                 else
35                     printf( "%I64d", k );
36             }
37             else
38             {
39                 LL temp = m - n;
40                 if( temp & 1 )
41                     printf( "%I64d", k - 1 );
42                 else
43                 {
44                     if( ( k - m ) & 1 )
45                         printf( "%I64d", k - 2 );
46                     else
47                         printf( "%I64d", k );
48                 }
49             }
50         }
51         printf( "\n" );
52     }
53     return 0;
54 }
55
56 template< typename Q >
57 void inin( Q &x )
58 {
59     x=0;
60     int f=0;
61     char ch;
62     scanf( "%c", &ch );
63     while( ch < ‘0‘ || ch > ‘9‘ )
64     {
65         if( ch == ‘-‘ )
66             f = 1;
67         scanf( "%c", &ch );
68     }
69     while( ch >= ‘0‘ && ch <= ‘9‘ )
70     {
71         x = x*10 + ch - ‘0‘;
72         scanf( "%c", &ch );
73     }
74     x = f?-x:x;
75 }

C题链接:https://codeforces.com/contest/1036/problem/C

C题AC代码:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include <malloc.h>
 6 #include <stdbool.h>
 7 #include <ctype.h>
 8
 9 typedef long long ll;
10
11 ll Arr[20][4];
12 int dig[20];
13 ll dp( int, int, int );
14 ll calc(ll);
15
16 int main()
17 {
18     memset( Arr, -1, sizeof(Arr) );
19     int i, T=0;
20     ll L,R;
21     while( ~scanf( "%d", &T ) )
22     {
23         for ( i = 1; i <= T; i ++ )
24         {
25             scanf( "%I64d%I64d", &L, &R );
26             L--;
27             printf( "%I64d\n", calc(R) - calc(L) );
28         }
29     }
30     return 0;
31 }
32
33 ll dp( int len, int res, int lim )
34 {
35     if ( res > 3 )
36         return 0;
37     if ( len == 0 )
38         return 1;
39     if ( !lim && Arr[len][res] > 0 )
40         return Arr[len][res];
41     ll ret = 0;
42     int up = 9;
43     if (lim)
44         up=dig[len];
45     int i;
46     for ( i = 0; i <= up; i ++ )
47         ret += dp( len-1, res+(i>0), lim && ( i == up ) );
48     if (!lim) Arr[len][res]=ret;
49     return ret;
50 }
51
52 ll calc(ll x)
53 {
54     int _sum = 0;
55     while (x)
56     {
57         dig[ ++ _sum ] = x % 10;
58         x /= 10;
59     }
60     return dp( _sum, 0, 1 );
61 }

全部测过样例再提交,另外,本蒟蒻还从未做过D……

原文地址:https://www.cnblogs.com/25th-engineer/p/9649460.html

时间: 2024-08-28 22:10:31

Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码的相关文章

Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers

看到数论就懵了,题目有两个解法,第一个解法是组合数学的内容,解析用英文写的,看不懂:第二个解法是暴力搜索的,找了网上用同样方法的中文注释代码才看明白.首先如果直接枚举肯定玩完,要找些其他办法.题目中用到了dfs,或者叫暴力搜索,但是思路很巧妙.函数设计了三个参数,分别是搜索层数lev,代表10的次方数:当前处理的数字cu,为了不越界,用long long型:非0位数的个数cnt.如果层数超过了18,就应该返回.设置一个vector,存long long型数据,每次如果没返回,就把这个数加进vec

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 85 (Rated for Div. 2)

Educational Codeforces Round 85 (Rated for Div. 2) A. Level Statistics 签到题, 要求第一位维单增, 第二维变化比第一维慢, 直接模拟即可 B. Middle Class 题目大意 每个人有一些财富, 财富值超过x的人称为富人, 由于实行共产主义, 你可以将某些人的财产重新分配使得富人最多 解题思路 直接按财富值排序, 从大到小加入富人集合, 如果当前富人集合财富平均值小于x就break掉 C. Circle of Monst

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html