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. 关于word文档中目录的switch

    有很多的switch,下面这篇文章介绍的比较详细,可以参考:http://word.mvps.org/FAQs/Formatting/TOCSwitches.htm

  2. 使用 window.getSelection() 方法获取鼠标划取部分的起始位置和结束位置的问题(高亮后不能正确获取)

    如果没有高亮等复杂处理,只需要获取一段文字中选取的字和位置,那么 使用window.getSelection()获取div中选中文字内容及位置 怎么获取textarea中选中文字 则可以满足需求: - ...

  3. URL大小写敏感之谜

    URL其实就是我们浏览器地址栏的地址,一般由三部分组成: 协议名称,一般就是http 域名,也就是主机名 资源路径 如链接:http://www.w3school.com.cn/js/js_obj_r ...

  4. springMVC笔记二

    第十四章 springmvc快速入门(注解版本) 1)springmvc快速入门(传统版) 步一:创建springmvc-day02这么一个web应用 步二:导入springioc,springweb ...

  5. Java 如何正确停止一个线程

    自己在做实验性小项目的时候,发现自己遇到一个问题:如何控制线程的"死亡"? 首先,如何开启一个线程呢? 最简单的代码: public class Main { public sta ...

  6. MySQL in查询优化

    https://blog.csdn.net/gua___gua/article/details/47401621 MySQL in查询优化<一> 原创 2015年08月10日 17:57: ...

  7. 【HDU 4300 Clairewd’s message】

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  8. [USACO Hol10] 臭气弹 图上期望概率dp 高斯

    记住一开始和后来的经过是两个事件因此概率可以大于一 #include<cstdio> #include<iostream> #include<cstdlib> #i ...

  9. 收藏一个漂亮的Flash焦点图切换

    网上闲逛的时候发现一个Flash焦点图效果,跟喜欢,然后就下载回来,收集在这里,以便以后方便取用.这个Flash使用方法也是相当简单的,如果你喜欢,也可以从这里查看源代码下载. Flash 焦点图效果 ...

  10. Welcome to ShangHai <码农上漂记>

    来上海这边快三周了,一切都还算顺利,多亏了朋友们的帮助,要不就得街头打地铺了.对于上海这样的大都市,年轻的我们都想挤一挤,凑凑热闹,实现自己的小小抱负.然而不是每个人都混的起的.以前的我还总想着来大城 ...