HD-ACM算法专攻系列(17)——find your present (2)
题目描述:


源码:
#include"iostream"
#include"string"
using namespace std; bool IsFirstHalf(string *strs, int n, string str)
{
int count = 0;
for(int i = 0; i < n; i++)
{
if(str < strs[i])count++;
}
return count >= (n / 2 + n % 2);
} int main()
{
int n, count[100], counts[5];
string **strs;
strs = new string*[5];
for(int i = 0; i < 5; i++)
{
strs[i] = new string[100];
}
while(cin>>n)
{
if(n < 0)break;
counts[1] = counts[2] = counts[3] = counts[4] = 0;
for(int i = 0; i < n; i++)
{
cin>>count[i]>>strs[0][i];
if(count[i] > 0 && count[i] < 5)
{
strs[count[i]][counts[count[i]]++] = strs[0][i];
}
}
for(int i = 0; i < n; i++)
{
switch(count[i])
{
case 5:
cout<<100<<endl;
break;
case 0:
cout<<50<<endl;
break;
default:
if(IsFirstHalf(strs[count[i]], counts[count[i]], strs[0][i]))
{
cout<<55 + 10 * count[i]<<endl;
}
else
{
cout<<50 + 10 * count[i]<<endl;
}
break;
}
}
cout<<endl;
}
return 0;
}
HD-ACM算法专攻系列(17)——find your present (2)的更多相关文章
- HD-ACM算法专攻系列(23)——Crixalis's Equipment
题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的 ...
- HD-ACM算法专攻系列(21)——Wooden Sticks
题目描述: AC源码: 此题考查贪心算法,解题思路:首先使用快速排序,以w或l按升序排序(注意相等时,应按另一值升序排序),这样就将二维变量比较,变为了一维的,排好序的一边就不需要去管了,只需要对未排 ...
- HD-ACM算法专攻系列(22)——Max Sum
问题描述: AC源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前i各之和为负数时,直接选择以第i+1个为开头,在于当前i各之和为正数时,第i个可以不用作为开头(因为前i+1个之和一定大于 ...
- HD-ACM算法专攻系列(20)——七夕节
问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int mai ...
- HD-ACM算法专攻系列(19)——Leftmost Digit
问题描述: AC源码: 解题关键是,数据很大,不能强算,需要使用技巧,这里使用科学计算法,令N^N=a*10^n ,取对数后变为 N*log10(N)=log10(a)+n,令x = log10(a) ...
- HD-ACM算法专攻系列(18)——Largest prime factor
题目描述: 源码: 需要注意,若使用cin,cout输入输出,会超时. #include"iostream" #include"memory.h" #defin ...
- HD-ACM算法专攻系列(16)——考试排名
问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorith ...
- HD-ACM算法专攻系列(15)——Quoit Design
问题描述: 源码: 经典问题——最近邻问题,标准解法 #include"iostream" #include"algorithm" #include" ...
- HD-ACM算法专攻系列(14)——find your present (2)
问题描述: 源码: #include"iostream" #include"algorithm" using namespace std; bool cmp(i ...
随机推荐
- Java数组操作工具
原文地址:http://blog.csdn.net/qq446282412/article/details/8913690 2013-05-11 10:27 看到网上的一段关于对数组操作的代码,觉 ...
- ndk编译curl以及使用
百度搜ndk curl,大多都是转发的同一篇文章,文章中提供的lcur_config.h,不一定适合你的curl版本. 后来找到http://download.csdn.net/download/cs ...
- nutz 自定义sql的使用
虽然提供了Cnd,但是用起来是觉得有点不方便,然后就直接编写Sql语句.nutz提供了一些方法. Nutz.Dao 的自定义 SQL 部分的解决方案是: // 不推荐使用 用户可以硬编码 SQL 语句 ...
- prevent阻止标签默认行为&stop阻止事件冒泡
<form id="vm" v-on:submit.prevent="register"> 1.prevent是preventDefault,阻止标 ...
- Airtest多设备跑
一. 一个脚本对应一台设备 核心点:组织运行命令:将组织好的命令传到pool进程池(注意:是进程池,不是线程池,python的线程池不是同步执行,是按序执行) 以下不需要看,为私人项目备份目的. ...
- Spring Boot 项目学习 (三) Spring Boot + Redis 搭建
0 引言 本文主要介绍 Spring Boot 中 Redis 的配置和基本使用. 1 配置 Redis 1. 修改pom.xml,添加Redis依赖 <!-- Spring Boot Redi ...
- C++进阶 STL(3) 第三天 函数对象适配器、常用遍历算法、常用排序算法、常用算数生成算法、常用集合算法、 distance_逆序遍历_修改容器元素
01昨天课程回顾 02函数对象适配器 函数适配器是用来让一个函数对象表现出另外一种类型的函数对象的特征.因为,许多情况下,我们所持有的函数对象或普通函数的参数个数或是返回值类型并不是我们想要的,这时候 ...
- 自我介绍About me
我的github:www.github.com/dcdcbigbig 欢迎来加star!(雾) tm就是个菜逼
- Qt QImage与OpenCV Mat转换
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51029382 应一个朋友的要求,整理总 ...
- java陷阱之spring事物未提交和回滚导致不可预知问题
案发现场 //防止全局配置了 所以这里定义sprnig 不托管事物 @Transactional(propagation = Propagation.NOT_SUPPORTED) public boo ...