您的位置:首页 > 其它

Codeforces Round #407 (Div. 2)解题报告

2017-04-01 12:06 369 查看
好遗憾没参加这场比赛……vp取得了目前最高的名次orz

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: