BestCoder 2nd Anniversary(1001 + 1002 + 1003)
来源:互联网 发布:php的错误日志在哪里 编辑:程序博客网 时间:2024/04/28 08:26
1001 Oracle
http://acm.hdu.edu.cn/showproblem.php?pid=5718
题意:将n的各个数位重新排列,并将其分成两个不含前导零的正整数。
请你帮助他求出这两个正整数最大的和。如果不存在这样的两个正整数,输出”Uncertain”.
RE一次,数组开小了,,,这种情况貌似经常出现…
解法是:将其分成n-1位的数 加 一个1位的数。字符串模拟大数相加。注意不合法的情况。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 1e7 + 100;char s[N], ans[N];bool comp(char a,char b){ return a > b;}int main(){ int T; scanf("%d\n",&T); while(T--) { gets(s); sort(s,s+strlen(s),comp); if(s[1]=='0' || strlen(s) == 1) { printf("Uncertain\n"); continue; } else{ int i; for(i=0;s[i];i++) { if(s[i]=='0') break; } int mark = i-1,t = 0; for(i=0;s[i];i++) { if(i!=mark) ans[t++] = s[i]; } ans[t] = '\0'; if(s[mark] -'0' + ans[t-1]-'0' < 10) { ans[t-1] = s[mark]-'0' + ans[t-1]; printf("%s\n",ans); } else{ int jin = 1; ans[t-1] = s[mark]-'0' + ans[t-1] -'0' -10 + '0'; for(i = t-2; i>=0; i--) { int tmp = ans[i] -'0'; if(jin + tmp >=10) ans[i] = (jin + tmp) %10 +'0',jin = 1; if(jin==0) break; } if(jin==1) printf("1"); printf("%s\n",ans); } } } return 0;}
1002 Arrange
题意:这儿共有n堆稻谷,编号为1到n。Psyche需要将这些谷堆以某种顺序排列,设最终排在第i位的谷堆是Ai。
她得知了一些该排列的要求:
对于任意整数i∈[1,n] ,A1,A2,…,Ai 的最小值为Bi 。
对于任意整数i∈[1,n],A1,A2,…,Ai 的最大值为Ci 。
现在想知道,共有多少种合法的排列。由于答案可能很大,输出时对998244353取模。
解法: B[1]和C[1]肯定是必须要相等的。
然后保证 b[i] <= b[i-1] && c[i] >=c[i-1]的。
其次 b[i] 和 b[i-1] ,C[i] 和 C[i-1] 至少有一个是保持不变的。
当其只有一个改变的时候,这以为是确定的,只有一种方法。
当其两个都不改变的时候,可以放得种类数为 C[i] - B[i] + 1 - (i -1)。
因为每一位所放得数必须在 C[i] ~ B[i] 之间, 而前面i-1位已经放了这个范围里面 i-1个数。
比赛的时候真是傻逼…
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int N = 1e5 + 100;int b[N],c[N];const int MOD = 998244353;int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&b[i]); for(int i=1;i<=n;i++) scanf("%d",&c[i]); if(b[1]!=c[1]) { printf("0\n"); continue; } LL ans = 1; bool flag = true; for(int i=2;i<=n;i++) { if( b[i] > b[i-1] || c[i] < c[i-1]) flag = false; bool flag1 = (b[i] == b[i-1]); bool flag2 = (c[i] == c[i-1]); if(flag1 && flag2) ans = ans*(c[i] - b[i] - i + 2 ) % MOD; if(!flag1 && !flag2) flag = false; if(!flag) break; } if(!flag) ans = 0; printf("%I64d\n",ans); } return 0;}
1003 Wool
题意: 有 N个数,然后有个区间[L,R]。问这个区间内有多少个数 可以与N个数任意两个都不能组成三角形。
解法: 假如a,b为三角形的两条边,那么第三条边满足 a-b < c && a+b > c。然而找n个数的可行范围复杂度很高。联想到,当(a>=b) 的时候,b越大,则第三条边c的可行范围越大。所以把N个数每个数都当做a边来枚举一次,a[i] 和 a[i+1]之间都有一个可行范围。然后排序后将范围扫描一次就可得结果。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const LL N = 1e5 + 100;LL arr[N];struct Node{ LL l,r; Node(){} Node(LL a,LL b) : l(a),r(b){} friend bool operator < (const Node &a, const Node &b) { if(a.l != b.l) return a.l < b.l; else return a.r < b.r; }}P[N];int main(){ LL T; scanf("%I64d",&T); while(T--) { LL n,L,R; scanf("%I64d %I64d %I64d",&n,&L,&R); for(LL i=1;i<=n;i++) scanf("%I64d",&arr[i]); sort(arr+1,arr+1+n); for(LL i=1;i<n;i++) P[i] = Node( arr[i+1] - arr[i] +1, arr[i+1] + arr[i] -1); sort(P+1,P+n); LL tmin = P[1].l, tmax = P[1].r; LL ans = 0; for(LL i=2;i<n;i++) { if(P[i].l > tmax) { LL cnt = min(tmax,R) - max(tmin,L) + 1; ans += cnt>0 ? cnt:0; tmin = P[i].l ; tmax = P[i].r; } else if(P[i].l <= tmax) tmax = max(P[i].r,tmax); } LL cnt = min(tmax,R) - max(tmin,L) + 1; ans += cnt>0 ? cnt:0; printf("%I64d\n",R - L + 1 - ans); } return 0;}
总结: 思路有点慢,比赛的时候有点方。 代码水平还很低。主要原因是 比赛的时候思绪混乱,没有好好想就开始写,然后越写越乱。还要注意多测几组样例再交,不要紧张,罚时更划不来。平时也要养成多测样例的好习惯。
- BestCoder 2nd Anniversary(1001 + 1002 + 1003)
- BestCoder 2nd Anniversary 1001~1003
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- 【HDOJ】【BestCoder 2nd Anniversary】1003 Wool
- BestCoder 2nd Anniversary 1002/hdu5719 Arrange
- BestCoder 2nd Anniversary #1001-oracle
- BestCoder 2nd Anniversary - 1001 Oracle
- BestCoder 2nd Anniversary 1001/hdu5718 Oracle
- BestCoder 2nd Anniversary-1005
- BestCoder 2nd Anniversary Oracle
- BestCoder 2nd Anniversary Arrange
- BestCoder 2nd Anniversary Palace
- BestCoder 2nd Anniversary HDU5720
- BestCoder 2nd Anniversary Oracle
- ubuntu试用小练手
- 动态规划之最长公共子序列
- hudson插件开发入门(一)
- 数据结构之Trie
- 百度地图SDK和百度定位SDK的使用(笔记)
- BestCoder 2nd Anniversary(1001 + 1002 + 1003)
- Swift中文教程(二十一) 协议
- Mybatis深入了解(七)----延迟加载
- HDU1576(扩展欧几里得算法)
- 百度地图学习第一篇-项目的搭建和配置
- JavaScript 闭包及其机制
- 游戏测试----------------第4章
- Android开发相关的Blog推荐——跟随大神的脚步才能成长为大神
- Java的抽象类