2015四川省acm B题
来源:互联网 发布:rbac权限管理表mysql 编辑:程序博客网 时间:2024/04/28 16:00
Carries
frog has
Unfortunately, frog is somehow afraid of carries (进位). She defines hardness
Find the total hardness adding
Input
The input consists of multiple tests. For each test:
The first line contains
Output
For each test, write
Sample Input
2 5 5 10 0 1 2 3 4 5 6 7 8 9
Sample Output
1 20
原题链接: http://acm.scu.edu.cn/soj/problem.action?id=4437
题意:给出几组测试数据,要求分别输出每组数的所有元素相加会发生多少次进位,输出进位数。
方法:分别求每位上的的进位数,直接快速排序,然后两个指针扫描。
代码如下:
#include<iostream>#include<algorithm>#include<cmath>#define maxn 100005using namespace std;long long int mergesort(int a[],int begin,int end) { int b[maxn]; long long num; long long count=0; int n=end+1,p; int q,r; for(int k=1;;k++) { p=0,q=0,r=end; num=pow(10,k); for(int i=0;i<n;i++) { b[i]=a[i]%num; if(b[i]!=a[i]) { p=1; } } sort(b,b+n); while(r!=q) { if(b[q]+b[r]>=num) { count+=r-q; r--; } else { q++; } } if(p==0) break; } return count; }int main(void) { int n,a[maxn]; while(cin>>n) { for(int i=0;i<n;i++) cin>>a[i]; cout<<mergesort(a,0,n-1)<<endl; } return 0; }
- 2015四川省acm B题
- 四川省ACM省赛B题,优先队列+BFS Charitable Exchange
- 2015ACM四川省赛C题
- 2015 四川省赛 B. Carries
- scu oj 4437: Carries (2015年四川省程序ACM设计竞赛B题目 )
- SCU 4437 Carries (2015四川省省赛B题)
- 2015 四川省赛 B Carries (脑洞题)
- scu oj 4439 : Vertex Cover(2015年四川省程序ACM设计竞赛D题 )
- scu oj 4439 : Vertex Cover(2015年四川省程序ACM设计竞赛D题 )
- scu oj 4442 Party(2015年四川省acm程序设计竞赛)
- UESTC 482 Charitable Exchange(四川省赛B题)
- 2016年四川省TI杯电子设计竞赛B题
- SOJ 4445 2015四川省赛模拟题
- scu oj 4443 Range Query (scoure :2015年四川省acm省赛)
- scu oj 4442 Party(2015年四川省acm程序设计竞赛)★ ★ ★
- scu oj 4442 Party(2015年四川省acm程序设计竞赛)(*)
- scu oj 4443 Range Query (source :2015年四川省acm省赛)(*)
- BNUOJ 52296 Nearest Neighbor Search(2016ACM-ICPC四川省赛A题)
- 基于MySQL实现按距离排序、范围查找geoHash
- 数据库查询语句总结
- 【机房重构】——怎么用EA画时序图
- HDU 2006
- 需要记住的SQL查询语句
- 2015四川省acm B题
- 自我学习
- Mysql导入导出时遇到的问题
- 2013 2014 2015 2016 Xiyou Linux Group 免试题揭秘
- 更改Eclipse中的Project Explorer的字体
- 【C++ STL系列】迭代器 iterator
- 我来到上海
- 谁需要在x86上使用内存屏障呢?
- 讲义一 java语言特点