Carries
Carries
frog has nn integers a1,a2,…,ana1,a2,…,an, and she wants to add them pairwise.
Unfortunately, frog is somehow afraid of carries (进位). She defines hardness h(x,y)h(x,y)for adding xx and yy the number of carries involved in the calculation. For example, h(1,9)=1,h(1,99)=2h(1,9)=1,h(1,99)=2.
Find the total hardness adding nn integers pairwise. In another word, find
.
Input
The input consists of multiple tests. For each test:
The first line contains 11 integer nn (2≤n≤1052≤n≤105). The second line contains nnintegers a1,a2,…,ana1,a2,…,an. (0≤ai≤1090≤ai≤109).
Output
For each test, write 11 integer which denotes the total hardness.
Sample Input
2
5 5
10
0 1 2 3 4 5 6 7 8 9
Sample Output
1
20
//题意: n 个数,C(n,2) 这两个数可能进位,问,所有的进位次数是多少?
//题解: 容易想到,枚举可能进位的位置,最多也就9次么,然后二分找可能进位的个数
答案要LL,还wa了一发
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define LL long long
#define lowbit(x) ((x)&(-x))
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MOD 1000000007 inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 100005
/**************************/
int n;
int a[MX];
int yu[MX]; int bi_search(int l,int r,int w)
{
int pos = -;
while (l<=r)
{
int mid = (l+r)/;
if (yu[mid]>=w)
{
pos = mid;
r = mid-;
}
else l = mid+;
}
return pos;
} int main()
{
while (scanf("%d",&n)!=EOF)
{
int mmm=;
for (int i=;i<=n;i++)
{
a[i] =scan();
mmm = max(mmm,a[i]);
}
LL ans = ;
int y = ;
while(y)
{
y*=;
for (int i=;i<=n;i++)
yu[i] = a[i]%y;
sort(yu+,yu++n);
for (int i=;i<=n;i++)
{
int pos = bi_search(,n,y-(a[i]%y));
if (pos!=-)
{
int num = n-pos+;
if (a[i]%y<yu[pos]) ans += (LL)num;
else ans += (LL)num-;
}
}
if (y>mmm) break;
}
printf("%lld\n",ans/);
}
return ;
}
Carries的更多相关文章
- ACM:SCU 4437 Carries - 水题
SCU 4437 Carries Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice ...
- 2015弱校联盟(1) - B. Carries
B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...
- HDU 4588 Count The Carries 数学
Count The CarriesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- HDU 4588 Count The Carries 计算二进制进位总数
点击打开链接 Count The Carries Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java ...
- Carries SCU - 4437
Carries frog has nn integers a1,a2,-,ana1,a2,-,an, and she wants to add them pairwise. Unfortunately ...
- 二分 + 模拟 - Carries
Carries Problem's Link Mean: 给你n个数,让你计算这n个数两两组合相加的和进位的次数. analyse: 脑洞题. 首先要知道:对于两个数的第k位相加会进位的条件是:a%( ...
- HDU 4588 Count The Carries(数学统计)
Description One day, Implus gets interested in binary addition and binary carry. He will transfer al ...
- hdu4588Count The Carries
链接 去年南京邀请赛的水题,当时找规律过的,看它长得很像数位dp,试了试用数位dp能不能过,d出每位上有多少个1,然后TLE了..然后用规律优化了前4位,勉强过了. 附数位dp代码及找规律代码. #i ...
- HDU 4588 Count The Carries(找规律,模拟)
题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #includ ...
随机推荐
- 倍福TwinCAT(贝福Beckhoff)应用教程13.2 TwinCAT控制松下伺服 CS说明
虚拟仿真上,要注意仿真只是为了可视化,可以看到数据的变动是否和实际一致,所以Robot2D才是主要因素,虚拟仿真采集机器人的关节位置或者TCP位置来显示而已,为了测试一些别的算法,我们还可以在虚拟仿真 ...
- 我的superui开源后台bootstrap开发框架
我的superui开源后台bootstrap开发框架:http://git.oschina.net/tzhsweet/superui
- HDU 4632 Palindrome subsequence(区间dp)
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- JAVA-IO操作,字节-字符转换流
掌握OutputStreamWriter和InputStreamReader类的作用 一般操作输入输出内容的时候,就需要使用字节或字符流,但是,有些时候,需要将字符流变成字节流形式,或者字节流变成字符 ...
- js使用ctrl+s保存表单提升用户体验
本质上是监控ctrl+s 然后触发相应事件 <script language="JavaScript"> //Ctrl+s保存 document.onkeydown=f ...
- NSTimer 增加引用计数, 导致内存泄露,
self.adTimer = [NSTimerscheduledTimerWithTimeInterval:5.0target:selfselector:@selector(handleADIma ...
- iOS:一个Cell中设置另外一个Cell中的button
场景: 子类化Cell中有button,拥有选中式样,点击第一个Cell中的button后,Cell一中的button获得选中式样.可是当点击Cell二中的button时.Cell一中的button选 ...
- POJ-3134-Power Calculus(迭代加深DFS)
Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multipli ...
- vue 父组件如何调用子组件的函数Methods
答案就是使用ref即可. <countdown ref="countdown"></countdown> beforeDestroy () { // 切换页 ...
- sshd服务安装和配置管理
1.SSHD简介(介绍) SSH协议:安全外壳协议,为Secure Shell的缩写,SSH为建立在应用层和传输层基础上的安全协议. sshd服务使用SSH协议可以用来进行远程控制,或在计算机之间传送 ...