CS Academy Round #49 A, B, C
来源:互联网 发布:linux下输入ftp命令 编辑:程序博客网 时间:2024/05/21 12:42
A.Odd Sum
题目链接
https://csacademy.com/contest/round-49/task/odd-sum/statement/
题解
给组数让求其中两两组合可以形成奇数的个数
直接统计奇数偶数个数相乘
AC代码
#include <bits/stdc++.h>using namespace std;#define LL long long#define CLR(a,b) memset(a,(b),sizeof(a))const int MAXM = 1e3+10;const int MAXN = 1e5+10;const int mod = 1e9+7;int arr[MAXN];int main(){ int n; scanf("%d",&n); int x; int k2 = 0, k1 = 0; for(int i = 0;i < n; i++) { scanf("%d",&x); if(x&1) k1++; else k2++; } printf("%d\n",k1*k2);return 0;}
B.Money Machine
题目链接
https://csacademy.com/contest/round-49/task/money-machine/
题解
很裸的贪心
AC代码
#include <bits/stdc++.h>using namespace std;#define LL long long#define CLR(a,b) memset(a,(b),sizeof(a))const int MAXM = 1e3+10;const int MAXN = 1e5+10;const int mod = 1e9+7;int arr[MAXN];int main(){ int n, c, x1, u, x2; scanf("%d%d%d%d%d",&n,&c,&x1,&u,&x2); int ans = 0; for(int i = 1; i <= n; i++) { if(c>=u && u < (n-i+1)*x2) { c -= u; ans += x2; //printf("%d %d %d\n",c,u,ans); } c = c + x1 + ans; } printf("%d\n",c);return 0;}
C.Max Substring
题目链接
https://csacademy.com/contest/round-49/task/max-substring/
题解
英语是硬伤啊,硬是看成了暴力KMP,字符串问题
时间复杂度
判断
AC代码
//标称emmmmmmm...#include <bits/stdc++.h>using namespace std;#define LL long long#define CLR(a,b) memset(a,(b),sizeof(a))const int MAXM = 1e3+10;const int MAXN = 1e5*4;const int mod = 1e9+7;string str;vector<int> pos[26];int main(){ cin>>str; int len = str.size(); // get the positions for all charactes for(int i = 0; i < len; i++) { pos[str[i]-'a'].push_back(i); } // get the max numgber of ocueences of a character int maxx = 0; for(int i = 0; i < 26; i++) { maxx = max(maxx,(int)pos[i].size()); } string mx_answer = ""; for(int i = 0; i < 26; i++) { int sz = 1; if((int)pos[i].size() != maxx) continue; while(pos[i].back()+sz < len) { char ch = str[pos[i][0]+sz]; bool flag = true; //for(auto it = pos[i].begin(); it != pos[i].end(); it++) for(auto it : pos[i]) { if(str[it+sz] != ch) flag = false; } // the end characters are not equal if(!flag) break; // all good ,continue trying to increase size sz++; } // actually compute a string of length 'size' to compare it with the max string string c_str = ""; for(int j = 0; j < sz; j++) { c_str += str[pos[i][0]+j]; } // if the size is bigger or the string is smaller lexicographically // update the answer if(sz>(int)mx_answer.size() || sz>c_str.size()) mx_answer = c_str; } cout<<mx_answer<<'\n';return 0;}
阅读全文
0 0
- CS Academy Round #49 A, B, C
- CS Academy Round #43 A B C D
- CS Academy Round #44 A B C D
- CS Academy Round #49 C.Max Substring
- CS Academy Round #49 C.Max Substring 【后缀数组】
- CS Academy Round #32 Light Count
- CS Academy Round #33 Subinterval Division
- CS Academy Round #50 D.Min Races
- CS Academy Round #30 (Div. 2 only) C.Constant Sum(树状数组,区间修改,单点查询模板)
- Codeforces Beta Round #1 A B C
- Codeforces Beta Round #1 A B C
- Codeforces Beta Round #2 A B C
- Codeforces Round #231 A,B,C
- BestCoder Round #7-A,B,C
- BestCoder Round #8 A,B,C
- Codeforces Round #278(Div2) A B C
- BestCoder Round #29 A,B,C
- Codeforces Round #300 A B C
- TP5 url链接(带参数)的写法
- C#回顾学习笔记十九:类和对象
- 关于String类型变量的比较问题
- python try except 捕获所有异常
- Spring及其优点
- CS Academy Round #49 A, B, C
- 《深入理解Java虚拟机》——Java内存区域与内存溢出异常学习总结
- 冷静一下,openwrt之总结
- Unity技巧总结02 GUI绘制 Loading遮罩
- Jvisualvm监控远程linux下Tomcat
- 3.比较yield和return
- JAVA 单元测试框架
- 总结2: Batch Normalization反向传播公式推导及其向量化
- (转转)2018校园招聘开发类试题0917