C. Cheap Kangaroo
time limit per test

1.0 s

memory limit per test

256 MB

input

standard input

output

standard output

There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants to eat exactly xi food. The kangaroos all want to order the same size of plates, but each one can order more than one plate for themselves if they need to. If the kangaroo orders more than he needs, he can simply hide the leftovers in his pouch.

At this Indian restaurant, the cost of the plate is the same as its size. Since Karl the Kangaroo is paying and is low on money, he wants to know what is the minimum cost to feed all N kangaroos and what is the largest possible size of the plates that satisfies this minimum cost?

Input

The first line of input is T – the number of test cases.

The first line of each test case is an integer N (1 ≤ N ≤ 105).

The second line contains N space-separated integers xi (1 ≤ xi ≤ 109).

Output

For each test case, output a line containing two space-separated integers – the minimum cost and the maximum plate size that corresponds to when the total cost is minimized.

Example
input
2
1
5
2
4 2
output
5 5
6 2

思路:题意不说了,应该都看得懂,这题乍一看感觉很难,但其实最低价就是每个人都用容量为1的盘子,这样是不会产生浪费的,而满足最低价的最大盘子,肯定是所有数的最大公约数了.

实现代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
ll t,n,x,y;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
scanf("%lld",&x);
if(n==){
printf("%lld %lld\n",x,x);
}
else{
ll sum = x;
ll ans = x;
for(int i = ; i < n;i ++){
scanf("%lld",&y);
sum += y;
ans = gcd(ans,y);
}
printf("%lld %lld\n",sum,ans);
}
}
}
 
H. Mirrored String I
time limit per test

1.0 s

memory limit per test

256 MB

input

standard input

output

standard output

The gorillas have recently discovered that the image on the surface of the water is actually a reflection of themselves. So, the next thing for them to discover is mirrored strings.

A mirrored string is a palindrome string that will not change if you view it on a mirror.

Examples of mirrored strings are "MOM", "IOI" or "HUH". Therefore, mirrored strings must contain only mirrored letters {A, H, I, M, O, T, U, V, W, X, Y} and be a palindrome.

e.g. IWWI, MHHM are mirrored strings, while IWIW, TFC are not.

A palindrome is a string that is read the same forwards and backwards.

Can you tell if string S is a mirrored string?

Input

The first line of input is T – the number of test cases.

Each test case contains a non-empty string S of maximum length 1000. The string contains only uppercase English letters.

Output

For each test case, output "yes" (without quotes) if the string S is a mirrored string, otherwise output "no".

Example
input
3
IOI
ARABELLA
RACECAR
output
yes
no
no

思路:

水题

实现代码:

#include<bits/stdc++.h>
using namespace std; int main()
{
char s[];
char a[] = "AHIMOTUVWXY";
int n;
cin>>n;
while(n--){
scanf("%s",s);
int len = strlen(s);
int flag,flag1 = ;
for(int i = ;i < len;i++){
flag = ;
for(int j = ;j < ;j++){
if(s[i]==a[j]){
flag = ;
break;
}
}
if(flag == ){
cout<<"no"<<endl;
flag1 = ;
break;
}
}
if(flag1) continue;
for(int i = ;i < len/;i++){
if(s[i]!=s[len-i-]){
cout<<"no"<<endl;
flag1 = ;
break;
}
}
if(flag1) continue;
else
cout<<"yes"<<endl;
}
return ;
}
M. Make Cents?
time limit per test

6.0 s

memory limit per test

256 MB

input

standard input

output

standard output

Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this year, but that’s irrelephant. What’s important is that the location of the competition might not have been the same every year. Therefore, after every trip, he always has leftover money in the currency of the country he visited.

Now he wants to see how much Jordanian Dinars he has after all those competitions. Can you help him convert the leftover money from all competitions to Jordanian Dinar, if that makes any cents?

Input

The first line of input is T – the number of test cases.

The first line of each test case contains C and N (1 ≤ C, N ≤ 100000), the number of currency types and the number of competitions, respectively.

The next C lines each contain the name of the currency Ci of maximum length 10 in lowercase and/or uppercase letters, and the value Viof that currency in Jordanian Dinar (0 < Vi ≤ 1000). The names are case-sensitive.

The next N lines each contains an amount left over from each competition (0 ≤ Ni ≤ 1000), and the name of the currency of that amount (it is guaranteed that the name was either given in the input or is “JD”).

Output

For each test case, print on a single line the total amount of money he has in Jordanian Dinar(JD) rounded to 6 decimal digits.

Example
input
1
3 5
dollar 0.71
euro 0.76
turkish 0.17
5.1 dollar
6 dollar
7 turkish
3 euro
1.1 JD
output
12.451000

思路:

水题

实现代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,m;
double x;
char s[];
scanf("%d",&t);
while(t--){
double ans = 0.0;
map<string,double>mp;
scanf("%d%d",&n,&m);
mp["JD"] = ;
for(int i = ;i <= n;i ++){
scanf("%s",s);
string s1 = s;
scanf("%lf",&x);
mp[s1] = x;
}
for(int i = ;i <= m;i ++){
scanf("%lf",&x);
scanf("%s",s);
string s1 = s;
ans += x*mp[s1];
}
printf("%.6lf\n",ans);
mp.clear();
}
}

gym101350 c h m的更多相关文章

  1. APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试

    此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...

  2. 关于apue.3e中apue.h的使用

    关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...

  3. YYModel 源码解读(二)之NSObject+YYModel.h (1)

    本篇文章主要介绍 _YYModelPropertyMeta 前边的内容 首先先解释一下前边的辅助函数和枚举变量,在写一个功能的时候,这些辅助的东西可能不是一开始就能想出来的,应该是在后续的编码过程中 ...

  4. YYModel 源码解读(一)之YYModel.h

    #if __has_include(<YYModel/YYModel.h>) FOUNDATION_EXPORT double YYModelVersionNumber; FOUNDATI ...

  5. error RC1015: cannot open include file 'afxres.h' 解决办法

    在为WindowsPhone8程序添加本地化的过程中遇到这个问题: 问题原因就是afxres.h文件缺失,下载它,放到VS安装目录下的VS\include目录下就可以了(选择目录的时候注意对应对版本) ...

  6. afxcomctl32.h与afxcomctl32.inl报错

    afxcomctl32.h与afxcomctl32.inl报错 编译公司一个几年前的老项目,是从VC6.0升级到VS2005的. 1.编译时报缺少头文件,于是附件包含目录,于是出现了以下报错: 1&g ...

  7. C标准头文件<math.h>

    定义域错误可以理解为超出了函数的适用范围,如果发生了定义域错误,设errno为EDOM 如果结果不能表示为double值,则发生值域错误,如果结果上溢,则函数返回HUGE_VAL的值,设errno为E ...

  8. C标准头文件<ctype.h>

    主要包括了一些字符识别和转换函数 字符判断 isalnum() //函数原型 #include<ctype.h> int isalum(int c); 功能:如果输入的字符是字母(alph ...

  9. xcode中的.h和.m文件分别是什么意思?各有什么用?

    .h 表示头文件,用来声明各种成员变量,方法,属性之类的.在import的时候用头文件. .m 主要用来实现.h 里声明的方法.举个例子,如果要写一个方法,你要在.h里先声明: - (void)myM ...

随机推荐

  1. 串口通信DMA中断

    这是以前学32的时候写的,那时候学了32之后感觉32真是太强大了,比51强的没影.关于dma网上有许多的资料,亲们搜搜,这里只贴代码了,其实我也想详详细细地叙述一番,但是自己本身打字就慢,还有好多事情 ...

  2. day59

    轮播图作业 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF ...

  3. pv,uv的意义

    PV(page view),即页面浏览量,或点击量;通常是衡量一个网络新闻频道或网站甚至一条网络新闻的主要指标. 高手对pv的解释是,一个访问者在24小时(0点到24点)内到底看了你网站几个页面.这里 ...

  4. 《图说VR入门》——DeepoonVR的大鹏(陀螺仪)枪

    <图说VR入门>--VR大朋的(陀螺仪)枪 本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接: http://blog.csdn.net/cartzhang/ar ...

  5. 表单设置 disabled 后无法传值到后台的解决办法

    在提交 from 表单时,下面的 input 无法正常提交给后台, 发现,如果input的字段设为disabled,该表单是无法提交的. <input type="text" ...

  6. .NetCore实践爬虫系统(二)自定义规则

    回顾 上篇文章NetCore实践爬虫系统(一)解析网页内容 我们讲了利用HtmlAgilityPack,输入XPath路径,识别网页节点,获取我们需要的内容.评论中也得到了大家的一些支持与建议.下面继 ...

  7. sql优化详细介绍学习笔记

    因为最近在面试,发现sql优化这个方面问的特别特别的多.之前都是零零星星,不够全面的了解一点,刚刚在网上查了一下,从 http://blog.csdn.net/zhushuai1221/article ...

  8. Android与单片机通信常用数据转换方法(汇总)

    下面直接贴代码 1.  将GB2312转化为中文,如BAFAC2DCB2B7→胡萝卜,两个字节合成一个文字 public static String stringToGbk(String string ...

  9. KVM虚拟机管理——虚拟机创建和操作系统安装

    1. 概述2. 交互式安装2.1 图形化-本地安装2.1.1 图形化本地CDROM安装2.2.2 图形化本地镜像安装2.2 命令行-本地安装2.2.1 命令行CDROM安装2.3 图形化-网络安装2. ...

  10. chrome播放m3u8視頻失败

    由于项目后台需要播放m3u8视频,但此视频格式在移动端和Safari支持比较友善但是PC浏览器中都不太尽如人意,所以想在Chrome中播放只能借助第三方插件来播放. 有一款Video.js插件极大的简 ...