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. 计算机视觉-sift(1)原理

    1999年由David Lowe首先发表于计算机视觉国际会议(International Conference on Computer Vision,ICCV),2004年再次经David Lowe整 ...

  2. jqgrid 宽度自适应

    当jqgrid所在操作区宽度大于了给各列设置宽度之和时,此时表格的宽度未铺满操作区,效果不理想 此时,可以通过配置宽带自适应来现实表格内容自动铺满. 配置属性 shrinkToFit:ture 若要启 ...

  3. DRUPAL7 : 安装中文版本时遇到的问题

    http://yeenav.com是基于Drupal 7+汉化资源 搭建. 期间遇到一些麻烦, 做个记录. 首先把语言包drupal-7.0.zh-hans.po 放在htdocs/drupal-7. ...

  4. 【转】MySQL执行计划分析

    原文:http://www.cnblogs.com/wangyanhong/archive/2013/09/18/3327919.html 一.语法explain <sql语句>例如: e ...

  5. odoo之显示前端,数据,可选择

    def create(self,cr,uid,vals,context=None): if context is None: context ={} if vals.get('name','/')== ...

  6. 5213 Exp3 免杀原理与实践

    5213 Exp3 免杀原理与实践 任务一:正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,自己利用shellcode编程等免杀工具或技巧 使用msf编码器 ...

  7. Python+Matplotlib制作动画

    注: 在"实验设计与数据处理"的课后作业中,有一个数据可视化的作业,利用课程上学习的某种方法找一个二维函数的最大值,并将这个寻找的过程可视化.在作业里面利用了Matplotlib的 ...

  8. koa2 入门(1)koa-generator 脚手架和 mongoose 使用

    项目地址:https://github.com/caochangkui/demo/tree/koa2-learn 1 构建项目 1.1 安装koa-generator $ npm install -g ...

  9. ASYNC_IO_COMPLETION

    项目组有一个数据库备份的Job运行异常,该Job将备份数据存储到remote server上,平时5个小时就能完成的备份操作,现在运行19个小时还没有完成,backup命令的Wait type是 AS ...

  10. Neo4j 第四篇:使用C#更新和查询Neo4j

    本文使用的IDE是Visual Studio 2015 ,驱动程序是Neo4j官方的最新版本:Neo4j Driver 1.3.0 ,创建的类库工程(Project)要求安装 .NET Framewo ...