HDU 5718 oracle BestCoder 2nd Anniversary
2016-07-22 16:27
459 查看
题解说的比我好多啦,我就不赘述了。
1001 Oracle
Provider : cxzxxjd
尤其要注意最小的数不为0;
PS:关于时限为1s的问题:
已验证,手写sort可以在1S内。。。我写了个312ms的
如果你要一秒,可以试试不用sort,用桶排试试,应该可以在1s内。
1001 Oracle
Provider : cxzxxjd
先记录 0-9这10个数字分别有多少个。 不难看出,最小的一个存在的数字和其余的数字降序排列的相加就是答案, 但是最小的那个数字不能是0,因为题面上说明是正整数。 将这两个数加起来时,注意处理进位问题。 考虑无解的情况,即一串数字中仅存在1个非0数字或不存在。 (PS.这道题目原本的时限是1s,考虑到题目的难度和评测机的问题,开了4s,大家可以自己在FST以后看一下时间。 如果是时限是1s的话,sort是过不了的,输出也需要优化一下) 时间复杂度 O(Tn)O(Tn)。
尤其要注意最小的数不为0;
//Oracle #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const long long maxn = 10000005; char n[maxn]; int nn[maxn]; int main() { int tt; scanf("%d",&tt); while(tt--){ memset(n,0,sizeof(n)); memset(nn,0,sizeof(nn)); scanf("%s",&n); int len = strlen(n); sort(n,n+len); long long cnt = 0; int x = 0; for(int i = 0; i < len-1; i++){ if(n[i] == '0') cnt++; if(n[i] != '0'){x = i;break;} } if (cnt == len-1){printf("Uncertain\n");} else if (cnt >= 1&&cnt<len-1) { for (int i = len-1; i >= x; i--) { nn[i] = n[i] - '0'; } int m = 0; for (int i = len+2; i > x; i--) { if(m == 0 && nn[i]==0) continue; printf("%d",nn[i]); m = 1; } for(int i = 0; i < x-1;i++) printf("0"); printf("%d",nn[x]); printf("\n"); } else{ for (int i = len-1; i >= 1; i--){ nn[i] = n[i] - '0'; } int a = n[0]-'0'; nn[1] = nn[1] + a; for(int i = 1; i < len; i++){ if(nn[i]>=10){ nn[i+1]+=1; nn[i]%=10; } } int m = 0; for (int i = len+2; i > 0; i--){ if(m == 0 && nn[i]==0) continue; printf("%d",nn[i]); m = 1; } printf("\n"); } } return 0; }
PS:关于时限为1s的问题:
已验证,手写sort可以在1S内。。。我写了个312ms的
如果你要一秒,可以试试不用sort,用桶排试试,应该可以在1s内。
相关文章推荐
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- Oracle Containers for J2EE远程安全漏洞(CVE-2014-0413)
- Oracle 10g R2不能使用EM的问题
- 表空间操作
- PreparedStatement中in子句的处理
- VMware下RedHat4.8_64位安装Oracle 10g RAC--简略脚本
- oracle sql日期比较
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- OS block size和Oracle block size,查找OS Blocksize的方法
- oracle中创建数据库和表空间的几点总结
- 数据库自动备份脚本
- oracle的nvl函数的使用介绍
- 解决oracle用户连接失败的解决方法
- oracle的一些tips技巧
- Oracle 下的开发日积月累
- Oracle存储过程之数据库中获取数据实例
- Windows下ORACLE 10g完全卸载的方法分析
- Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
- ORACLE LATERAL-SQL-INJECTION 个人见解