Codeforces Round #407 (Div. 2)解题报告
2017-04-01 12:06
369 查看
好遗憾没参加这场比赛……vp取得了目前最高的名次orz
A. Anastasia and pebbles
向上取整处理即可。
View Code
A. Anastasia and pebbles
向上取整处理即可。
1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <queue> 8 typedef long long ll; 9 typedef unsigned long long ull; 10 using namespace std; 11 const int MAX=2e3+5; 12 const int INF=1e6; 13 bool an[MAX]; 14 int vi[MAX]; 15 queue<int> que; 16 int n,k; 17 int tem; 18 int main() 19 { 20 scanf("%d%d",&n,&k); 21 fill(vi,vi+2002,INF); 22 for(int i=1;i<=k;i++) 23 { 24 scanf("%d",&tem); 25 an[tem]=true; 26 } 27 vi[1000]=0; 28 que.push(1000); 29 while(!que.empty()) 30 { 31 tem=que.front();que.pop(); 32 for(int i=0;i<=1000;i++) 33 { 34 if(!an[i]) 35 continue; 36 int he=i+tem-n; 37 if(he<0||he>2000) 38 continue; 39 else 40 { 41 if(he==1000) 42 { 43 printf("%d\n",vi[tem]+1);return 0; 44 } 45 else if(vi[he]==INF) 46 { 47 vi[he]=vi[tem]+1; 48 que.push(he); 49 } 50 } 51 } 52 } 53 printf("-1\n"); 54 return 0; 55 }
View Code
相关文章推荐
- [Codeforces]Round246 div2 解题报告
- Codeforces Round #306 (Div. 2) D.E. 解题报告
- 【解题报告】Codeforces Round #303 (Div. 2)
- Croc Champ 2013 - Round 2 (Div. 2 Edition) E. Cube Problem 解题报告
- Codeforces Round #382 (Div. 2) 解题报告
- Codeforces Round #469 (Div. 2) 解题报告
- Codeforces Round #283 (Div. 2) 解题报告(A B C)
- Codeforces Round #223 (Div. 2) 解题报告
- Codeforces Round #225 (Div. 2)A:Coder 解题报告
- Codeforces Round #262 (Div. 2)解题报告
- codeforces_233_div2解题报告
- Codeforces Round #372 (Div. 1) B. Complete The Graph 解题报告
- 【解题报告】Codeforces Round #372 (Div. 2)
- Codeforces Round #453 (Div. 1)解题报告(ABCD)
- topcoder SRM588 DIV1 解题报告
- Codeforces AIM Tech Round (Div. 2)解题报告
- codeforces Round #269(div2) C解题报告
- RCC 2014 Warmup (Div. 2) 解题报告
- Codeforces Round #382 (Div. 2)解题报告
- codeforces Round #273(div2) D解题报告