Educational Codeforces Round 50 (Rated for Div. 2)的ABC三题AC代码

Posted 25th-engineer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 50 (Rated for Div. 2)的ABC三题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
", ( 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( "
" );
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
", 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……

技术分享图片

以上是关于Educational Codeforces Round 50 (Rated for Div. 2)的ABC三题AC代码的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27