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

Misaki 邀请NN个朋友去做摩天轮,每个朋友都进入一个缆车,如果哪个朋友满足:"(他的缆车的值+左边一个缆车的值)%INT_MAX=右边一个缆车的值",那么可以得到Misaki的一个吻,第1个缆车的左边是第KK个车,右边是第2个车,第KK个车的左边是第k-1k−1个,右边是第1个. 请帮Misaki计算一下她要吻多少次。你可以假设当所有人进入缆车后,没有空缆车,一个车装有多个朋友也是合法的.
多组测试数据
每组测试数据第一行一个NN表示有NN个朋友。
第二行有NN个整数,val[i]val[i]表示第ii个朋友的缆车的值。
1<=n<=1001<=n<=100;
0<=val[i]<=0<=val[i]<= INT_MAX INT_MAX 为 21474836472147483647
对于每组测试数据,输出Case #x: answer; 如果只有一个缆车,输出-1.
3
1 2 3
5
1 2 3 5 7
6
2 3 1 2 7 5
Case #1: 1
Case #2: 2
Case #3: 3
对于第三个样例,当他们进入缆车后,缆车的值是{{1},{2}, {3}, {5}, {7}},但第二个缆车有两个朋友,所以答案是3.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
typedef long long LL;
using namespace std;
const int Max=;
const int MOD=;
struct node
{
LL value,num;
node(int xx,int yy):value(xx),num(yy){}
node(){}
bool operator < (const node &another) const
{
return value<another.value;
}
}a[Max];
map<int,int>book;
map<int,int>idx;
int main()
{
int n,ca=,x,y;LL sum;
while(~scanf("%d",&n))
{
book.clear();
idx.clear();
int top=,wei;
for(int i=;i<n;i++)
{
scanf("%d",&x);
book[x]++;
if(book[x]==)
{
a[top].value=x;
a[top].num=;
idx[x]=top;
top++;
}
else
{
wei=idx[x];
a[wei].num=book[x];
}
}
if(top==) {printf("Case #%d: -1\n",ca++);continue;}
sort(a,a+top);
int ans=;
for(int i=;i<top;i++)
{
// cout<<a[i].value<<" ";
if(i==)
{
sum=a[n-].value+a[].value;
if(sum%MOD==a[].value) ans+=a[].num;
}
else if(i==n-)
{
sum=a[n-].value+a[n-].value;
if(sum%MOD==a[].value) ans+=a[n-].num;
}
else
{
sum=a[i-].value+a[i].value;
if(sum%MOD==a[i+].value) ans+=a[i].num;
}
}
printf("Case #%d: %d\n",ca++,ans);
}
return ;
}
hdu 5174 Ferries Wheel的更多相关文章
- hdu 5174(计数)
Ferries Wheel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 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 5174
题意有点不明白,因为MAX为int最大值,推测为64位,AC #include <cstdio> #include <iostream> #include <cstrin ...
- hdu 5175(数论)
Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- BestCoder Valentine's Day Round
昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法). 1001,也就是 hdu ...
- Misaki's Kiss again(hdu5175)
Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 4424 & zoj 3659 Conquer a New Region (并查集 + 贪心)
Conquer a New Region Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3461 Code Lock(并查集+二分求幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3461 A lock you use has a code system to be opened in ...
- hdu 1038 Biker's Trip Odometer(水题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1038 Biker's Trip Odometer Time Limit: 2000/1000 MS ...
随机推荐
- MapReduce03
======================== MapReduce 2.0基本架构 ======================== Client -------------> 与MapRed ...
- Uva 11151 - Longest Palindrome
A palindrome is a string that reads the same from the left as it does from the right. For example, I ...
- XAML实例教程系列 - 资源(Resources)
Kevin Fan分享开发经验,记录开发点滴 XAML实例教程系列 - 资源(Resources) 2012-08-10 12:47 by jv9, 1386 阅读, 1 评论, 收藏, 编辑 在Wi ...
- MSP430:串口输出
初始化 void Uart_Init(void) { BCSCTL1 = CALBC1_1MHZ; // Set DCO DCOCTL = CALDCO_1MHZ; P1SEL = BIT1 + BI ...
- E20170619-hm
bucket n. 水桶; open hash [词典] [计] 开放散列,开混列; spirit n. 精神,心灵; 情绪; 勇气; 精髓; flesh n. 肉; 肉体; 果肉; 皮 ...
- Factstone Benchmark(数学)
http://poj.org/problem?id=2661 题意:Amtel在1960年发行了4位计算机,并实行每十年位数翻一番的策略,将最大整数n作为改变的等级,其中n!表示计算机的无符号整数(n ...
- BZOJ 4828 DP+BFS
被一道简单BFS坑了这么长时间我也是hhh了 //By SiriusRen #include <bits/stdc++.h> using namespace std; ,,):d(D),x ...
- 普通平衡树代码。。。Treap
应一些人之邀...发一篇代码 #include <iostream> #include <cstdio> #include <cstdlib> #include & ...
- JVM中线程状态转换图
JVM中线程的状态转换图 线程在一定条件下,状态会发生变化.线程一共有以下几种状态: 1.新建状态(New):新创建了一个线程对象. 2.就绪状态(Runnable):线程对象创建后,其他线程调用了该 ...
- bootstrap 字体颜色 对齐方式
一:字体代码:作用--颜色 1..text-muted:提示--浅灰色 2..text-primary:主要--蓝色 3..text-success:成功--浅绿色 4..text-info: ...