hdu 5174(计数)
Ferries Wheel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1651 Accepted Submission(s): 494
Today,Misaki invites N
friends to play in the Ferries Wheel.Every one will enter a cable car.
One person will receive a kiss from Misaki,if this person satisfies the
following condition: (his/her cable car's value + the left car's value
) % INT_MAX = the right car's value,the 1st car’s left car is the kth car,and the right one is 2nd car,the kth car’s left car is the (k−1)th car,and the right one is the 1st car.
Please
help Misaki to calculate how many kisses she will pay,you can assume
that there is no empty cable car when all friends enter their cable
cars,and one car has more than one friends is valid.
For each case,the first line is a integer N(1<=N<=100) means Misaki has invited N friends,and the second line contains N integers val1,val2,...valN, the val[i] means the ith friend's cable car's value.
(0<=val[i]<= INT_MAX).
The INT_MAX is 2147483647.
1 2 3
5
1 2 3 5 7
6
2 3 1 2 7 5
Case #2: 2
Case #3: 3
In the third sample, the order of cable cars is {{1},{2}, {3}, {5}, {7}} after they enter cable car,but the 2nd cable car has 2 friends,so the answer is 3.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = ;
typedef long long LL;
const LL mod = ;
LL val[N];
int cnt[N];
int main()
{
int n;
int t = ;
while(scanf("%d",&n)!=EOF){
memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++){
scanf("%lld",&val[i]);
}
sort(val+,val++n);
int k =;
int num=;
cnt[num]++;
for(int i=;i<=n;i++){
if(val[i]==val[i-]){
cnt[num]++;
}else{
num++;
cnt[num]++;
val[k++] = val[i];
}
}
printf("Case #%d: ",t++);
k--;
if(k==){
printf("-1\n");
continue;
}
int ans = ;
for(int i=;i<=k;i++){
if(i==){
if((val[]+val[k])%mod==val[]) ans+=cnt[];
}else if(i==k){
if((val[k-]+val[k])%mod==val[]) ans+=cnt[k];
}else{
if((val[i]+val[i-])%mod==val[i+]) ans+=cnt[i];
}
}
printf("%d\n",ans);
}
return ;
}
hdu 5174(计数)的更多相关文章
- Valentine's Day Round 1001.Ferries Wheel(hdu 5174)解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1] ...
- hdu 5116 计数
题目大意:给你n个点, n个点的坐标都在200以内,让你统计不相交的两个L形的种数,且L形的两条边长的gcd = 1. 思路:用二维树状数组维护点的信息,然后划分区块进行统计,题解是用总的减去相交的, ...
- hdu 5072 计数+容斥原理
/* 题意: 给出n个数(n<100000), 每个数都不大于100000,数字不会有重复.现在随意抽出3个,问三个彼此互质 或者 三个彼此不互质的数目有多少. 思路: 这道题反着想,就是三个数 ...
- hdu 5174 Ferries Wheel
摩天轮是一个环,周围围绕着一些缆车.每个缆车按顺序编号为1,2,3...K-1,K1,2,3...K−1,K而且每个缆车也拥有一个唯一的值且保证A[i-1] < A[i] < A[i+1] ...
- HDU 5174
题意有点不明白,因为MAX为int最大值,推测为64位,AC #include <cstdio> #include <iostream> #include <cstrin ...
- BestCoder Valentine's Day Round
昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法). 1001,也就是 hdu ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
随机推荐
- SQL SERVER 时间相关操作笔记
1.DATEADD函数: A. MSDN上的示例:http://msdn.microsoft.com/zh-cn/library/ms186819%28v=sql.90%29.aspx
- 《学习OpenCV》课后习题解答9
题目:(P126) 创建一个程序,使其读入并显示一幅图像.当用户鼠标点击图像时,获取图像对应像素的颜色值(BGR),并在图像上点击鼠标处用文本将颜色值显示出来. 解答: 本题关键是会用cvGet2D获 ...
- (转)MongoDB numa系列问题三:overcommit_memory和zone_reclaim_mode
内核参数overcommit_memory : 它是 内存分配策略 可选值:0.1.2.0:表示内核将检查是否有足够的可用内存供应用进程使用:如果有足够的可用内存,内存申请允许:否则,内存申请失败,并 ...
- 处理大并发量订单处理的 KafKa部署总结
处理大并发量订单处理的 KafKa部署总结 今天要介绍的是消息中间件KafKa,应该说是一个很牛的中间件吧,背靠Apache 与很多有名的中间件搭配起来用效果更好哦 ,为什么不用RabbitMQ,因为 ...
- [CF45G]Prime Problem
题目大意:将$1$到$n(1<n\leqslant6000)$分成若干组数,要求每组数的和均为质数,若存在一种分配方式,输出每个数所在的组的编号,有多组解输出任意一组解,若不存在,输出$-1$ ...
- [洛谷P2032]扫描
题目大意:有一串数,有一个长度为k的木板,求木板每次移动后覆盖的最大值 题解:单调队列 C++ Code: #include<cstdio> using namespace std; co ...
- BZOJ4567 [Scoi2016]背单词 【trie树 + 贪心】
题目链接 BZOJ4567 题解 题意真是鬼畜= = 意思就是说我们应先将一个串的所有后缀都插入之后再插入这个串,产生代价为其到上一个后缀的距离 我们翻转一下串,转化为前缀,就可以建\(trie\)树 ...
- C++——OOP面向对象理解
从Rob Pike 的 Google+上的一个推看到了一篇叫<Understanding Object Oriented Programming>的文章,我先把这篇文章简述一下,然后再说说 ...
- TSP问题之状压dp法
首先,我们先来认识一下什么叫做TSP问题 旅行商问题,即TSP问题(Traveling Salesman Problem)又译为旅行推销员问题.货郎担问题,是数学领域中著名问题之一.假设有一个旅行商人 ...
- POJ2240:Arbitrage(最长路+正环)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29374 Accepted: 12279 题目链接: ...