2016弱校连萌十一专场10.3 部分题解
来源:互联网 发布:写作文软件app 编辑:程序博客网 时间:2024/05/22 13:00
【比赛题目链接】https://www.bnuoj.com/v3/contest_show.php?cid=8504#info
【A】找两个数乘积是连续上升并且最大的。模拟即可。
【代码君】
////Created by just_sort 2016/10/3//Copyright (c) 2016 just_sort.All Rights Reserved//#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 1010;int a[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i = 1; i <= n; i++) scanf("%d",&a[i]); int ans = -1; for(int i = 1; i <= n; i++) { for(int j = 1; j < i; j++){ int tmp = a[i]*a[j]; int p = tmp%10; tmp /= 10; while(tmp) { int q = tmp%10; if(q + 1 != p) break; tmp /= 10; p = q; } if(tmp == 0) ans = max(ans,a[i]*a[j]); } } printf("%d\n",ans); } return 0;}【B】从终点开始bfs,记录各点到终点最短路。
【代码君】
////Created by just_sort 2016/10/3//Copyright (c) 2016 just_sort.All Rights Reserved//#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 220;const int inf = 0x3f3f3f3f;int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};struct node{int x,y;};queue<node>q;int dp[maxn][maxn];char G[maxn][maxn];int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int ans1,ans2; for(int i = 0; i < n; i++) scanf("%s",G[i]); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(G[i][j] == '%'){ q.push(node{i,j}); } } } ans1 = ans2 = inf; memset(dp,-1,sizeof(dp)); while(q.size()) { node now = q.front(); q.pop(); if(G[now.x][now.y] == '$') ans1 = min(ans1,dp[now.x][now.y]); if(G[now.x][now.y] == '@') ans2 = min(ans2,dp[now.x][now.y]); for(int i = 0; i < 4; i++) { int dx = now.x + dir[i][0]; int dy = now.y + dir[i][1]; if(dx >= 0 && dx < n && dy >= 0 && dy < m && G[dx][dy] != '#' && dp[dx][dy] == -1){ dp[dx][dy] = dp[now.x][now.y] + 1; q.push(node{dx,dy}); } } } if(ans2 < ans1) printf("Yes\n"); else printf("No\n"); } return 0;}
【C】n对括号最多需要交换n*(n+1)/2次()))...(((类似这种摆放情况),那么找最短的满足m*(m+1)/2>=n的,然后把额外需要交换的交换完毕就是结果
【代码君】
////Created by just_sort 2016/10/3//Copyright (c) 2016 just_sort.All Rights Reserved//#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;int main(){ int n; while(scanf("%d",&n)!=EOF) { int m = 1; while(m * (m + 1) / 2 < n) m++; string str; str = string(m,')')+string(m,'('); int now = m; for(int i = 0; i < m * (m + 1) / 2 - n; i++){ swap(str[now-1],str[now]); now--; } cout<<str<<endl; } return 0;}
【D】ACM协会中有
【解题方法】set大模拟,开两个集合,一个是
【代码君】
////Created by just_sort 2016/10/7//Copyright (c) 2016 just_sort.All Rights Reserved//#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5+6;struct node{ string s; int time; int d;};bool cmp(node a,node b){ if(a.d == b.d) return a.time > b.time; else return a.d>b.d;}struct cmp1{//从大到小排序 bool operator()(const node &a,const node &b)const{ if(a.d == b.d) return a.time > b.time; else return a.d > b.d; }};struct cmp2{//从小到大排序 bool operator()(const node &a,const node &b)const{ if(a.d == b.d) return a.time < b.time; else return a.d < b.d; }};set<node,cmp2>s1;set<node,cmp1>s2;map<string,node>mp;node a[maxn];int main(){ int n,m; while(scanf("%d",&n)!=EOF) { s1.clear(); s2.clear(); mp.clear(); double tmp = 1.0*n*0.2; int x = floor(tmp); node xx; for(int i = 1; i <= n; i++){ cin>>a[i].s>>a[i].d; a[i].time = i; mp[a[i].s] = a[i]; } int curn = n; sort(a+1,a+n+1,cmp); for(int i = 1; i <= x; i++){ s1.insert(a[i]); } for(int i = x + 1; i <= n; i++){ s2.insert(a[i]); } cin>>m; string s; for(int i = curn+1; i <= curn + m; i++){ char op[5]; scanf("%s",op); if(op[0] == '-')//'-' { cin>>s; xx = mp[s]; if(s1.erase(xx)) x--; s2.erase(xx); if(x > (int)(1.0*(n-1)*0.2)) { x--; xx = *s1.begin(); s1.erase(xx); s2.insert(xx); cout<<xx.s; printf(" is not working now.\n"); } n--; if(x < (int)(1.0*(n)*0.2)) { x++; xx = *s2.begin(); s1.insert(xx); s2.erase(xx); cout<<xx.s; printf(" is working hard now.\n"); } } else if(op[0] == '+') //'+' { cin>>a[i].s>>a[i].d; a[i].time = i; mp[a[i].s] = a[i]; if(x < (int)(1.0*(n+1)*0.2)) { if(a[i].d > (*s2.begin()).d || (a[i].d == (*s2.begin()).d && a[i].time > (*s2.begin()).time)) { s1.insert(a[i]); cout<<a[i].s; printf(" is working hard now.\n"); } else { xx = *s2.begin(); s2.erase(xx); s1.insert(xx); s2.insert(a[i]); cout<<a[i].s; printf(" is not working now.\n"); cout<<xx.s; printf(" is working hard now.\n"); } x++; } else { if(x != 0) { xx = *s1.begin(); if(a[i].d > xx.d || (a[i].d == xx.d && a[i].time > xx.time)) { s1.erase(xx); s1.insert(a[i]); s2.insert(xx); cout<<a[i].s; printf(" is working hard now.\n"); cout<<xx.s; printf(" is not working now.\n"); } else{ s2.insert(a[i]); cout<<a[i].s; printf(" is not working now.\n"); } } else{ xx = *s2.begin(); if((int)(1.0*(n+1)*0.2) > 0) { if(a[i].d > xx.d || (a[i].d == xx.d && a[i].time > xx.time)) { s1.insert(a[i]); cout<<a[i].s; printf(" is working hard now.\n"); } else{ s2.erase(xx); s2.insert(a[i]); s1.insert(xx); cout<<a[i].s; printf(" is not working now.\n"); cout<<xx.s; printf(" is working hard now.\n"); } } else{ s2.insert(a[i]); cout<<a[i].s; printf(" is not working now.\n"); } } } n++; } } } return 0;}
【E】贴个题解http://www.cnblogs.com/chen9510/p/5929542.html
【代码君】
////Created by just_sort 2016/10/3//Copyright (c) 2016 just_sort.All Rights Reserved//#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;typedef unsigned long long ull;const int maxn = 111111 + 10;int n;vector<int> g[maxn];map<ull, int> mp;ull dfs(int u, int f, int p) {ull res = 0;for (int i = 0; i < g[u].size(); ++i) {int v = g[u][i];res += dfs(v, u, p);}res = res * p + 1;mp[res]++;return res;}int main() {scanf("%d", &n);for (int i = 0; i < n - 1; ++i) {int u, v;scanf("%d%d", &u, &v);g[u].push_back(v);}mp.clear();dfs(1, 0, 1e9 + 7);ll ans = 0;map<ull, int>::iterator it;for (it = mp.begin(); it != mp.end(); it++) {ll x = it->second;ans += x * (x - 1) / 2;}printf("%lld\n", ans);}
0 0
- 2016弱校连萌十一专场10.3 部分题解
- 2016弱校联萌 十一专场 10.2
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校联盟十一专场10.3,BNU52308,大模拟
- (2016弱小联盟十一专场10.3)Parentheses 找规律
- (2016弱小联盟十一专场10.3) Best Matched Pair 暴力
- 2016弱校联盟十一专场10.3 C.We don't wanna work!(集合操作)
- 2016弱校联盟十一专场10.3 ABest Matched Pair(水)
- 2016弱校联盟十一专场10.3 We don't wanna work!
- (2016弱小联盟十一专场10.3) Help the Princess! BFS
- (2016 弱校联盟十一专场10.3) Similarity of Subtrees DFS + hash
- 题解(中秋专场)
- 题解(国庆专场)
- 2016弱校联盟十一专场10.2 Longest Increasing Subsequence
- [Contests]2016弱校联盟十一专场10.7
- ABCTF-2016-部分题解
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing bnu 52325
- 2016弱校联盟十一专场10.5 F. Fibonacci of Fibonacci
- 【python爬虫】python使用代理爬虫例子
- poj 3735 Training little cats 构造矩阵+稀疏矩阵加速连乘+矩阵快速幂
- hdu4941map应用
- HDU 5558 Alice's Classified Message(后缀自动机)
- 数据结构实验之栈八:栈的基本操作
- 2016弱校连萌十一专场10.3 部分题解
- 数据库之三范式
- web.xml中 error-page的正确用法
- linux挂载与卸载 mount umount
- 自定义高度与宽度都相等的RelativeLayout
- 磕磕绊绊,Spring+Mybatis多数据源配置mysql+oracle
- js垃圾回收机制
- 从留言板开始做网站(七)——服务端的数据验证和安全输入
- MyBatis浅谈