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. jqgrid 单击行启用行编辑,切换行保存原编辑行

    为了加速表格互动编辑,我们往往希望通过选中行就触发了行编辑,完成行编辑后,再选中另一个行做编辑,同时上一个编辑行被自动保存,直至完成需要的编辑内容. 页面效果可能如下: 1)设置需要编辑的列 edit ...

  2. Junit测试中找不到junit.framework.testcase

    在使用Junit进行测试时,出现如下问题: 找不到junit.framework.testcase 解决方法: 选中项目->属性->Java构建路径->库->添加外部jar 在 ...

  3. Python3入门(十一)——IO编程

    一.文件读写 python的文件操作和C是兼容的 1.读文本文件 读文件操作如下: f = open("F:/1.txt", "r") data = f.rea ...

  4. 利用IDA6.6进行apk dex代码动态调试

    网上公开IDA6.6已经有一段时间,这个版本有个好处就是可以动态调试java代码.正好现在需要动态调试,所以顺便练习一下. 根据android的官方文档,如果要调试一个apk里面的dex代码,必须满足 ...

  5. linux gz 解压缩

    Linux压缩保留源文件的方法:gzip –c filename > filename.gzLinux解压缩保留源文件的方法:gunzip –c filename.gz > filenam ...

  6. SQL调优日志--内存问题排查入门篇

    概述 很多系统的性能问题,是由内存导致的.内存不够会导致页面频繁换入换出,IO队列高,进而影响数据库整体性能. 排查 内存对数据库性能非常重要.那么我当出现问题的时候,我们怎么排查性能问题呢? 存在问 ...

  7. NodeJS旅程 : express - nodejs MVC 中的王牌

    express 正如ASP.NET MVC 在作为.net平台下最佳的 Mvc框架的地位一样,express在 node.js 环境也有着相同的重要性.在百度上 "nodejs expres ...

  8. Android Studio开发实用网站收集

    重点 1.Android Studio 调试技巧-断点调试 http://blog.csdn.net/qq_32452623/article/details/53769708 2.android st ...

  9. ag使用需要注意的问题

    1.  set env 对比服务器标准配置,修改本地 /etc/apache2/sites-available/default (远程链接服务器的办法: ssh 12x.xxx.xxx.xxx) 2. ...

  10. 《Linux内核设计与实现》读书笔记——第五章

    <Linux内核设计与实现>读书笔记--第五章 标签(空格分隔): 20135321余佳源 第五章 系统调用 操作系统中,内核提供了用户进程与内核进行交互的一组接口.这些接口让应用程序受限 ...