码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-09-14 23:54:59      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:problem   bsp   png   cst   ORC   int   else   rate   inf   

       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……

技术分享图片

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

标签:problem   bsp   png   cst   ORC   int   else   rate   inf   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!