数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门

 1 /*
 2     数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案;用到sprintf把数字转移成字符读入
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <cmath>
 9 #include <vector>
10 using namespace std;
11
12 const int MAXN = 1e2 + 10;
13 const int INF = 0x3f3f3f3f;
14 char s[MAXN];
15 char t[MAXN];
16
17 int main(void)        //Codeforces Round #306 (Div. 2) C. Divisibility by Eight
18 {
19     while (scanf ("%s", s) == 1)
20     {
21         bool ok = false;
22         for (int i=0; i<1000; ++i)
23         {
24             if (i % 8 == 0)    sprintf (t, "%d", i);
25             int p = 0;
26             for (int i=0; s[i] && t[p]; ++i)
27             {
28                 if (s[i] == t[p])    p++;
29             }
30             if (!t[p])    {puts ("YES");    printf ("%s\n", t);    ok = true;    break;}
31         }
32         if (!ok) puts ("NO");
33     }
34
35     return 0;
36 }
37
38 /*
39 3454
40 10
41 111111
42 */
时间: 2024-12-26 11:40:17

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight的相关文章

找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

题目传送门 1 /* 2 找规律/贪心:ans = n - 01匹配的总数,水 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 const int MAXN = 2e5 + 10; 12 const int INF =

Codeforces 707 C. Pythagorean Triples(找规律)——Codeforces Round #368 (Div. 2)

传送门 Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding t

DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

题目传送门 1 /* 2 DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <cstring> 7 #include <cmath> 8 #include <algorithm> 9 #include <vector> 10 #include <map> 11 #include

【排序】【规律】Codeforces Round #254 (Div. 2) - D. Rooter&#39;s Song

D. DZY Loves FFT Source http://codeforces.com/contest/445/problem/D Description Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w?×?h, represented by a re

暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

题目传送门 1 /* 2 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <string> 9 using namespace std; 10 11 const int MAXN = 5e2 + 10; 12 const int

数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

题目传送门 1 /* 2 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 3 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 4 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #in

暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

题目传送门 1 /* 2 暴力:O (n^2) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 #include <vector> 9 using namespace std; 10 11 const int MAXN = 1e4 + 10; 12 const int INF = 0x3f3f3f3f; 13 14

构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

题目传送门 1 /* 2 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! 3 */ 4 /************************************************ 5 Author :Running_Time 6 Created Time :2015-8-3 8:43:02 7 File Name :A.cpp 8 *************************************************/ 9 1

二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

题目传送门 1 /* 2 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 using namespace std; 8 9 const int MAXN = 5e2 + 10; 10 const int MAXM = 1e6 + 10; 11 const int INF = 0