2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
http://codeforces.com/contest/1070
A
给你一个d和s,求一个最小的数,使的能整除d,并且每位数的和为s。
如果确定了某n位数取模d的值,那么再计算同样的n位数,取模d也是相同的值时,就多此一举了。比如10%2 == 0 20%2 == 0 同样是两位数,取模2都是等于0。所以取最小的就可以了。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 1e3+10; 5 struct Nod{ 6 int d, s; 7 string str; 8 }; 9 bool vis[N/2][N*5]; 10 int d, s; 11 void bfs() { 12 queue<Nod> que; 13 que.push({0,0,""}); 14 vis[0][0] = 1; 15 while(que.size()) { 16 Nod nod = que.front(); 17 que.pop(); 18 if(nod.s > s) continue; 19 if(nod.d == 0 && nod.s == s) { 20 cout << nod.str << endl; 21 return; 22 } 23 for(int i = 0; i < 10; i ++) { 24 int dd = (nod.d*10+i)%d; 25 int ss = nod.s + i; 26 if(!vis[dd][ss]) { 27 vis[dd][ss] = 1; 28 que.push({dd,ss,nod.str+char(i+'0')}); 29 } 30 } 31 } 32 cout << -1 << endl; 33 } 34 35 int main() { 36 cin >> d >> s; 37 bfs(); 38 return 0; 39 }
D
扔垃圾问题,当天的垃圾可以今天扔也可以明天扔,但最后一天的垃圾必须当天扔。每k个垃圾要用一个垃圾袋。求用垃圾袋最小的数量。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 1e5+10; 5 6 int main() { 7 ll n, k; 8 cin >> n >> k; 9 ll ans = 0, x, pre = 0; 10 for(int i = 1; i <= n; i ++) { 11 cin >> x; 12 if(i == n) { 13 ans += (x+pre+k-1)/k; 14 break; 15 } 16 if(pre > 0) { 17 ans ++; 18 x = max(0LL,x - (k-pre)); 19 } 20 ans += x/k; 21 pre = x-x/k*k; 22 } 23 printf("%lld ",ans); 24 return 0; 25 }