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 ...
随机推荐
- PRML5-神经网络(2)
本节来自<pattern recognition and machine learning>第5章. 接(PRML5-神经网络(1)) 5.5NN中的正则化 NN的输入层和输出层的单元个数 ...
- js 产生随机数
这里整理了几个产生随机数的方法: 1.generateUUID() //获取一个唯一数 function generateUUID() { var d = new Date().getTime(); ...
- 学会如何使用Github进行托管代码和用markdown撰写心得
这次作业是学会如何使用Github进行托管代码和用markdown撰写心得. 1.掌握使用Git进行代码版本,使用github进行代码托管.(git使用,推荐imooc公开课: 公开课 ) 登录 gi ...
- React等开发工具记录
React Native :React 起源于 Facebook 的内部项目,结合了 Web 应用和 Native 应用的优势,可以使用 JavaScript 来开发 iOS 和 Android 原生 ...
- Codeforces round 1106
Div 2 536 题目链接 我还是太菜了.jpg E 傻逼DP直接做 我居然调了1.5h 我真的是太菜了.jpg 堆+扫描线直接维护每个位置的贪心结果 然后要么使用干扰 要么就接受贪心的结果 #in ...
- [Usaco2005 Open]Disease Manangement 疾病管理 BZOJ1688
分析: 这个题的状压DP还是比较裸的,考虑将疾病状压,得到DP方程:F[S]为疾病状态为S时的最多奶牛数量,F[S]=max{f[s]+1}; 记得预处理出每个状态下疾病数是多少... 附上代码: # ...
- 人的一生为什么要努力 &1
2018-06-25
- ccf201703-2学生排队
问题描述 体育老师小明要将自己班上的学生按顺序排队.他首先让学生按学号从小到大的顺序排成一排,学号小的排在前面,然后进行多次调整.一次调整小明可能让一位同学出队,向前或者向后移动一段距离后再插入队列. ...
- Ruby知识总结-一般变量+操作符+if+数组和哈希
ruby入门掌握其实很简单,下面对我司主要使用的部分入门做一个简单的归纳总结: 本文的文章结构: 1.变量 2.操作符 3.if~else~end .unless 4.数组(Array) 5.哈希(H ...
- Android开发——Android多进程以及使用场景介绍
个层级,具体可以查看Android开发--Android进程保活招式大全中1.1部分的内容,这里就不赘述了. 根据进程中当前活动组件的重要程度,Android 会将进程评定为它可能达到的最高级别.例如 ...