HDU—— 5174 Ferries Wheel
来源:互联网 发布:程序员爱逛的网站 编辑:程序博客网 时间:2024/06/05 14:03
本题开始之前,先讲解一个知识点——unique(),代码中有用到:
unique()函数是一个去重函数,STL中unique的函数 unique的功能是去除相邻的重复元素(只保留一个),还有一个容易忽视的特性是它并不真正把重复的元素删除。他是c++中的函数,所以头文件要加#include<iostream.h>,具体用法如下:
int num[100];unique(num,mun+n)返回的是num去重后的尾地址,之所以说比不真正把重复的元素删除,其实是,该函数把重复的元素一到后面去了,然后依然保存到了原数组中,然后返回去重后最后一个元素的地址,因为unique去除的是相邻的重复元素,所以一般用之前都会要排一下序。
题意:摩天轮有K个座位,分别标号为1,2,3...K−1,k,且A[i−1]<A[i]<A[i+1](1<i<K).Misaki 邀请N个朋友去做摩天轮,每个朋友都进入一个缆车,如果哪个朋友满足:"(他的缆车的值+左边一个缆车的值)%INT_MAX=右边一个缆车的值",那么可以得到Misaki的一个吻,第1个缆车的左边是第K个车,右边是第2个车,第K个车的左边是第k−1个,右边是第1个.
请帮Misaki计算一下她要吻多少次。你可以假设当所有人进入缆车后,没有空缆车,一个车装有多个朋友也是合法的.
解题思路:暴力,记录每个缆车出现的次数,排序去重,枚举缆车的值,判断是否满足那个等式即可
#include <iostream>#include <cstdio>#include <cstring>#include <map>#include <algorithm>using namespace std;long long array[111];map<long long,int> p;const long long mod = 2147483647;int main(){ //freopen("input.txt","r",stdin); int N,T = 1; while(~scanf("%d",&N)) { memset(array,0,sizeof(array)); p.clear(); for(int i = 0; i<N; i++) { scanf("%I64d",&array[i]); p[array[i]]++; } int cou = 0; sort(array,array+N); int len = unique(array,array+N) - array; for(int i = 0; i<len; i++) { if(i == 0 && (array[i]+array[len-1])%mod == array[i+1]) cou += p[array[i]]; else if(i == len-1 && (array[i]+array[i-1])%mod == array[0]) cou +=p[array[i]]; else if((array[i]+array[i-1])% mod == array[i+1]) cou +=p[array[i]]; } if(len == 1) printf("Case #%d: -1\n",T++); else printf("Case #%d: %d\n",T++,cou); } return 0;}
0 0
- HDU—— 5174 Ferries Wheel
- HDU 5174 Ferries Wheel
- HDU 5174 Ferries Wheel (暴力小模拟)
- Hdu 5174 Ferries Wheel(模拟)
- hdu 5174 Ferries Wheel(模拟)
- [Bestcoder] Valentine's Day Round 1001 - Ferries Wheel | HDU 5174
- hdu 5174 Ferries Wheel【模拟】【排序+去重】
- HDU 5147 Ferries Wheel(暴力 数组)——BestCoder Valentine's Day Round
- 【BestCoder】 HDOJ 5174 Ferries Wheel
- 【CUGBACM15级BC第30场 A】hdu 5174 Ferries Wheel
- hdu5174---Ferries Wheel
- hdoj_5174题Ferries Wheel
- Valentine's Day Round 1001 Ferries Wheel
- hdu5174 Ferries Wheel (暴力求解也是有艺术的)
- 有趣图表值——chart wheel
- wheel
- Wheel ProgressBar 实现之一——画一条弧
- Wheel ProgressBar 实现之二——画进度文本
- Windows下给SourceTree配置外部比较工具BeyondCompare
- 连接池--只在系统启动时启动一次
- 读取资源文件的工具类.
- Java的几种定时任务
- linux编译连接选项解析
- HDU—— 5174 Ferries Wheel
- Python:itertools模块
- 学习笔记-CIFAR10模型理解简述
- JAVA深入学习笔记之 NIO
- XCode中创建pch文件
- 对一个对象初始化内存图解
- LeetCode开始刷题
- acm2023
- JavaScript - js闭包