传送门
A:
就是他
1 2 3 4 5
| while (N) { printf("%d ", N % 10); N /= 10; }
|
B:
只要找到最大的数和最小的数,比较一下就可以
C:
全用低功率模式,看剩下多少电,能换几次的高功率
注意不能正好全用完电
还有答案不能大于turn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> T; LL a,b; while(T--) { cin >> N >> M >> a >> b; LL n = b*M; if(n >= N) { cout << "-1" <<endl; } else { LL m = N- n; LL k = a - b; LL ans = m / k; if(m % k == 0) ans--; cout << min(ans,M) <<endl; } } return 0; }
|
D:
!题意是同一个数量的糖果只能放一种
1.记录每种糖果的数量
2.对数量排序
3.糖果从数量少到多放,同一种数量放了,找最大的比现在数量小的数量放
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| vector<int> b; map<int,int> a; map<int,int> c;
int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> T; while(T--) { cin >> N; int x; for(int i = 0;i < N;i++) { cin >> x; a[x]++; } int ans = 0; for(auto it = a.begin();it!=a.end();it++) { b.push_back(it->second); } sort(b.begin(),b.end()); for(int i = 0;i < b.size();i++) { if(c.find(b[i]) == c.end()) { c[b[i]]=0; ans += b[i]; } else { int n = b[i]; while(n--) { if(c.find(n) == c.end()) { ans += n; c[n] = 0; break; } } } } cout << ans <<endl; a.clear(); b.clear(); c.clear(); } return 0; }
|
E:
这个很有意思啊,加了一个剪枝就能过了,数据比较友好
hard版即F题就不行了
1.用map存放过的字符串
2.注意特殊处理原串和空串
3.dfs函数采用全排列的思想,记录去除的坐标,从去一位到n-1位枚举
4.add函数string s(N-n,'0');
构造一个string初始化,然后根据flag改变,通过map询问
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| map<string,int> a; string str; int flag[MAX]; int cnt = 0; int ans = 0;
void add(int n) { string s(N-n,'0'); int cmt = 0; for(int i = 0;i < N;i++) { if(!flag[i]) s[cmt++] = str[i]; } if(a.find(s) == a.end()) { a[s] = 1; ans += n; cnt++; } } void dfs(int n,int deep,int m) { for(int i = n;i < N;i++) { if(i > n && str[i] == str[i-1]) continue; if(cnt == M) return; if(deep == m) { flag[i] = 1; add(m); flag[i] = 0; } else { flag[i] = 1; dfs(i+1,deep+1,m); flag[i] = 0; } } } int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> M; cin >> str; a[str] = 1; cnt++; for(int i = 1;i < N;i++) { dfs(0,1,i); } if(cnt == M) cout << ans <<endl; else if(cnt == M-1) cout << ans + N <<endl; else cout << "-1" << endl; return 0; }
|