Ferries Wheel

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1651    Accepted Submission(s): 494

Problem Description
The Ferries Wheel is a circle,rounded by many cable cars,and the cars are numbered 1,2,3...K−1,K in order.Every cable car has a unique value and A[i−1]<A[i]<A[i+1](1<i<K).


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.

 
Input
There are many test cases.
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.

 
Output
For each test case, first output Case #X: ,then output the answer, if there are only one cable car, print "-1";
 
Sample Input
3
1 2 3
5
1 2 3 5 7
6
2 3 1 2 7 5
 
Sample Output
Case #1: 1
Case #2: 2
Case #3: 3

Hint

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.

 
 
题意:有n个人,每个人都有一个 val ,如果 val 相同,就证明他们在同一个摩天轮的小格子里面,现在这 n 个人要座到摩天轮上去,每个摩天轮格子都有一个价值,现在如果某个格子的价值是 val ,左边是 val1 ,右边是 val2 ,如果 (val+val1)%MAX_INT == val2 ,那么这个里面的人就会得到Misaki一个吻,问最后有多少人会得到Misaki 的吻。
题解:排序后,统计每个摩天轮格子里面的人的个数,去重后计数。当只有一个格子时输出 -1 .
#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(计数)的更多相关文章

  1. 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] ...

  2. hdu 5116 计数

    题目大意:给你n个点, n个点的坐标都在200以内,让你统计不相交的两个L形的种数,且L形的两条边长的gcd = 1. 思路:用二维树状数组维护点的信息,然后划分区块进行统计,题解是用总的减去相交的, ...

  3. hdu 5072 计数+容斥原理

    /* 题意: 给出n个数(n<100000), 每个数都不大于100000,数字不会有重复.现在随意抽出3个,问三个彼此互质 或者 三个彼此不互质的数目有多少. 思路: 这道题反着想,就是三个数 ...

  4. hdu 5174 Ferries Wheel

    摩天轮是一个环,周围围绕着一些缆车.每个缆车按顺序编号为1,2,3...K-1,K1,2,3...K−1,K而且每个缆车也拥有一个唯一的值且保证A[i-1] < A[i] < A[i+1] ...

  5. HDU 5174

    题意有点不明白,因为MAX为int最大值,推测为64位,AC #include <cstdio> #include <iostream> #include <cstrin ...

  6. BestCoder Valentine's Day Round

    昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法). 1001,也就是 hdu ...

  7. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  8. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

随机推荐

  1. linux安装mysql之设置远程访问权限

    1.将3306端口加入防火墙 /sbin/iptables -I INPUT -p tcp --dport 3306-j ACCEPT  #添加端口3306/etc/rc.d/init.d/iptab ...

  2. 【Python】- 如何使用Visual Studio 2013编写python?

    安装Visual Studio 2013 1.VS2013下载安装略 安装python2.7 1.从官网下载python2.7,下载地址:https://www.python.org/getit/  ...

  3. Thread.currentThread().getContextClassLoader().loadClass(className)和Class.forName(className)的区别

    一.正文: 有去看开源框架的童鞋,应该会经常看到如下代码:Thread.currentThread().getContextClassLoader().loadClass(className),那这个 ...

  4. [C/C++] static在C和C++中的用法和区别

    转自:http://blog.csdn.NET/skyereeee/article/details/8000512 static的三个作用: (1)局部静态变量 (2)外部静态变量/函数 (3)静态数 ...

  5. IE6,7,8支持css圆角

    我们知道Webkit内核的浏览器支持-webkit-border-radius: 10px;属性(10px是圆角半径),可以直接解析出圆角;Firefox浏览器支持-moz-border-radius ...

  6. Codeforces数据结构(水题)小结

    最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...

  7. Linux SNMP 监控一些常用OID

    Linux SNMP 监控一些常用OID ===============linux服务器snmp常用oid http://www.haiyun.me/archives/linux-snmp-oid.h ...

  8. bug 跟蚊子的相似之处

    bug 跟蚊子的相似之处: 1.不知道藏在哪里. 2.不知道有多少. 3.总是在你即将睡觉休息的时候出现. 2 A:最近在看<一拳超人>,觉得咱们程序猿跟埼玉老师有点像啊! B:哪里像了? ...

  9. 【BZOJ4325】NOIP2015 斗地主 搜索+贪心

    这个东西考试的时候一眼以为状压就压炸了考试又了一下午.....最后我打出来发现后几个点10min都过不去,我大概算了一下,可能是吧.......最后一脸懵逼的我去怂了正解,我们发现只要确定了顺子就可以 ...

  10. 【bzoj2141】排队 [国家集训队2011]排队(魏铭) 树套树 线段树套替罪羊树

    这个题就是动态偏序对,每次操作做两个删除两个插入就好了. #include<cstdio> #include<iostream> #include<cstring> ...