gym101350 c h m
1.0 s
256 MB
standard input
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?
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).
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.
2
1
5
2
4 2
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);
}
}
}
1.0 s
256 MB
standard input
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?
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.
For each test case, output "yes" (without quotes) if the string S is a mirrored string, otherwise output "no".
3
IOI
ARABELLA
RACECAR
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 ;
}
6.0 s
256 MB
standard input
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?
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”).
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.
1
3 5
dollar 0.71
euro 0.76
turkish 0.17
5.1 dollar
6 dollar
7 turkish
3 euro
1.1 JD
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的更多相关文章
- APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试
此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...
- 关于apue.3e中apue.h的使用
关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...
- YYModel 源码解读(二)之NSObject+YYModel.h (1)
本篇文章主要介绍 _YYModelPropertyMeta 前边的内容 首先先解释一下前边的辅助函数和枚举变量,在写一个功能的时候,这些辅助的东西可能不是一开始就能想出来的,应该是在后续的编码过程中 ...
- YYModel 源码解读(一)之YYModel.h
#if __has_include(<YYModel/YYModel.h>) FOUNDATION_EXPORT double YYModelVersionNumber; FOUNDATI ...
- error RC1015: cannot open include file 'afxres.h' 解决办法
在为WindowsPhone8程序添加本地化的过程中遇到这个问题: 问题原因就是afxres.h文件缺失,下载它,放到VS安装目录下的VS\include目录下就可以了(选择目录的时候注意对应对版本) ...
- afxcomctl32.h与afxcomctl32.inl报错
afxcomctl32.h与afxcomctl32.inl报错 编译公司一个几年前的老项目,是从VC6.0升级到VS2005的. 1.编译时报缺少头文件,于是附件包含目录,于是出现了以下报错: 1&g ...
- C标准头文件<math.h>
定义域错误可以理解为超出了函数的适用范围,如果发生了定义域错误,设errno为EDOM 如果结果不能表示为double值,则发生值域错误,如果结果上溢,则函数返回HUGE_VAL的值,设errno为E ...
- C标准头文件<ctype.h>
主要包括了一些字符识别和转换函数 字符判断 isalnum() //函数原型 #include<ctype.h> int isalum(int c); 功能:如果输入的字符是字母(alph ...
- xcode中的.h和.m文件分别是什么意思?各有什么用?
.h 表示头文件,用来声明各种成员变量,方法,属性之类的.在import的时候用头文件. .m 主要用来实现.h 里声明的方法.举个例子,如果要写一个方法,你要在.h里先声明: - (void)myM ...
随机推荐
- 架构图+kubernetes 问题理解 -- kube-pproxy - endpoint
1.详述kube-proxy原理,一个请求是如何经过层层转发落到某个pod上的整个过程.请求可能来自pod也可能来自外部. 1.1kube-proxy为集群提供service功能,相同功能的pods对 ...
- Windows控制程序网站带宽及Qos(TOS或DSCP)
[基于策略的 Qos]位置:gpedit.msc->本地计算机策略->用户配置->Windows 设置->基于策略的 Qos
- 降阶法计算行列式方法有个地方有Bug(原文也已更正,此为更正后部分)
今天用此函数做方程求解时发现有误,特此更正: /// <summary> /// 降阶法计算行列式 /// </summary> /// <param name=&quo ...
- 20155209 林虹宇Exp2 后门原理与实践
Exp2 后门原理与实践 实验内容 一.使用netcat获取主机操作Shell,cron启动 使用netcat获取主机操作Shell Win获得Linux Shell 查看win的ip地址 windo ...
- [C/C++标准库]_[初级]_[转换UTC时间到local本地时间]
场景 1.如果有面向全球用户的网站, 一般在存储时间数据时存储的是UTC格式的时间, 这样时间是统一的, 并可以根据当地时区来进行准确的转换. 2.存储本地时间的问题就在于如果换了时区, 那么显示的时 ...
- Asp.Net_抓包解析xml文件为json
protected void Button1_Click(object sender, EventArgs e) { string Phone = this.Txt_Con.Text; string ...
- 读取配置文件的URL,使用httpClient发送Post和Get请求,实现查询快递物流和智能机器人对话
1.主要jar包: httpclient-4.3.5.jar httpcore-4.3.2.jar 2.目录结构如图所示: 3.url.properties文件如下: geturl=http:// ...
- 吉他软件Guitar Pro播放无声音的解决方法
系统环境:适用于Windows操作系统和macOS的Guitar Pro . 问题表现:已成功安装Guitar Pro ,但用Guitar Pro 播放时没有任何声音或播放失真. 解决方案:首先确保安 ...
- Scrapy持久化存储
基于终端指令的持久化存储 保证爬虫文件的parse方法中有可迭代类型对象(通常为列表or字典)的返回,该返回值可以通过终端指令的形式写入指定格式的文件中进行持久化操作; 执行输出指定格式进行存储:将爬 ...
- PAT甲题题解-1010. Radix (25)-二分搜索
题意:给出n1和n2,以及其中一个数的进制,问另一个数是多少进制的情况下,才会是两个数相等.不存在的话,则输出Impossible 这题思路很简单,但是要考虑的比较多,在简单题里面算是比较好的. 有两 ...