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, ...
 
随机推荐
- CentOS6.8单独编译安装PHP gd库扩展
			
# PHP-GD安装 #在安装之前可以先更新一下yum源,可以使用国内的阿里云源 yum -y install libjpeg-turbo-devel yum -y install freetype- ...
 - Java中WeakHashMap实现原理深究
			
一.前言 我发现Java很多开源框架都使用了WeakHashMap,刚开始没怎么去注意,只知道它里面存储的值会随时间的推移慢慢减少(在 WeakHashMap 中,当某个“弱键”不再正常使用时,会被从 ...
 - 【bzoj3514】Codechef MARCH14 GERALD07加强版  LCT+可持久化线段树
			
题目描述 N个点M条边的无向图,询问保留图中编号在[l,r]的边的时候图中的联通块个数. 输入 第一行四个整数N.M.K.type,代表点数.边数.询问数以及询问是否加密.接下来M行,代表图中的每条边 ...
 - P2730 魔板 Magic Squares
			
题目背景 在成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 题目描述 我们知道魔板的每一个方格都有一种颜色.这8种颜 ...
 - poj2814-拨钟问题-C语言-枚举算法
			
#include <stdio.h> #include <stdlib.h> /* 首先,我们考虑用长度为9的数组表示表盘的状态以及调表的操作,终止的条件是表盘状态数组所有元素 ...
 - Small things are better
			
Yesterday I had fun time repairing 1.5Tb ext3 partition, containing many millions of files. Of cours ...
 - [SDOI2016] 排列计数 (组合数学)
			
[SDOI2016]排列计数 题目描述 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰 ...
 - python 闭包与装饰器
			
1.闭包--返回子函数名 作用:使用子函数之外的父函数的变量 闭包就是你调用了一个函数a,这个函数a反悔了一个子函数名b,这个返回的函数b就叫做闭包 代码举例 def a(): test = 'aa' ...
 - Terminals Project
			
https://github.com/Terminals-Origin Terminals Project Terminals is a secure, multi tab terminal serv ...
 - PHP 扒一扒这些题目都考了哪些知识点
			
1.模除 题目: <?php echo -10%3; *结果* -1 分析:其实这道题的知识点是在考模除和正负号的关系,那么我们看一段进阶的代码 <?php echo "10%3 ...