CODEFORCES problem 105A.Transmigration
题目本身上手并不难,字符串处理+简单的排序。要注意的地方是浮点数的处理。
依据计算机中浮点数的表示原理,在实际编程的过程中即使用一个确定的整数(假设是1)给一个浮点变量赋值 在查看变量时会发现实际存储的值是0.99999…….可以注意到在使用原来的EPX*k时也有可能出现这样的情况,本来是准确值应该是100,浮点运算却会得到 99.999……
由于k只有两位小数,因此一个整数乘上k,最多还是只有两位
我们令
新的经验new_epx=epx*k+0.001
当然可以用任何比0.01小的数,都能在不会影响正确结果的前提下修正错误结果。
#include<stdio.h>
#include<string.h>
#include<math.h>
char f[][];
int c[];
int main()
{
int n,m;
double k;
char s[];
int x,t=,i,j,flag;
scanf("%d %d %lf",&n,&m,&k);
for(i=;i<=n;i++)
{
scanf("%s %d",s,&x);
if(x*k+0.001>=)
{
t++;
strcpy(f[t],s);c[t]=floor(x*k+0.001);
}
}
for(i=;i<=m;i++)
{
scanf("%s",s);
for(j=,flag=;j<=t;j++)
if(strcmp(s,f[j])==){flag=;break;}
if(!flag)
{
t++;
strcpy(f[t],s);
}
}
char ss[];
int xx;
for(i=;i<=t;i++)
for(j=i+;j<=t;j++)
{
if(strcmp(f[i],f[j])>)
{
strcpy(ss,f[i]);
strcpy(f[i],f[j]);
strcpy(f[j],ss);
xx=c[i];c[i]=c[j];c[j]=xx;
}
}
printf("%d\n",t);
for(i=;i<=t;i++)
printf("%s %d\n",f[i],c[i]);
return ;
}
CODEFORCES problem 105A.Transmigration的更多相关文章
- Codeforces Problem 708A Letters Cyclic Shift
题目链接: http://codeforces.com/problemset/problem/708/A 题目大意: 从字符串s中挑选出一个子串(非空),将该子串中的每个字母均替换成前一个字母,如' ...
- Codeforces Problem 778B Bitwise Formula
题目链接:http://codeforces.com/contest/779/problem/E 题意:有n个变量都可以用m位二进制数表示,这n个数的value将以两种格式中的一种给出 1.变量名, ...
- codeforces problem 140E New Year Garland
排列组合题 题意 用m种颜色的彩球装点n层的圣诞树.圣诞树的第i层恰由l[i]个彩球串成一行,且同一层内的相邻彩球颜色不同,同时相邻两层所使用彩球的颜色集合不同.求有多少种装点方案,答案对p取模. 只 ...
- Codeforces Problem 598E - Chocolate Bar
Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...
- Codeforces Problem - 38E - Let's Go Rolling!(DP)
E. Let's Go Rolling! time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 903G Yet Another Maxflow Problem - 线段树
题目传送门 传送门I 传送门II 传送门III 题目大意 给定一个网络.网络分为$A$,$B$两个部分,每边各有$n$个点.对于$A_{i} \ (1\leqslant i < n)$会向$A_ ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
随机推荐
- jquery readio checked
今天太鬼火了为这个难问题搜了一下午了到最后还是csdn的朋友给了我正确的答案http://bbs.csdn.net/topics/300162450谢谢这位朋友 // $("#ISOK1&q ...
- 支付宝-API接口解析-转账到银行
支付宝-API接口解析-转账到银行 扫码转账 测试地址 解析内容: alipays://platformapi/startapp?appId=09999988&actionType=toCar ...
- AlertDialog的实现
课程Demo 重点解析自定义对话框 public class MainActivity extends AppCompatActivity { private Button bt1; private ...
- 让TortoiseGit记住帐号密码方法
我的电脑环境是: Windows7 64x 系统用户名是:steden 所以,我的路径是:C:\Users\steden\ 具体要根据你的系统环境及当前用户名来决定. 在这里,有个文件:.gitc ...
- vue2.0生命周期函数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Ryubook_1_switch_hub_部署执行
一.环境: mininet.ovs.Ryu. 二.实验过程: 1.搭建拓扑: 执行sudo mn --topo single,3 --mac --switch ovsk --controller re ...
- jQuery radio 选中提示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 1434:【例题2】Best Cow Fences
1434:[例题2]Best Cow Fences 时间限制: 1000 ms 内存限制: 65536 KB提交数: 263 通过数: 146 [题目描述] 给定一个长度为n的 ...
- 解决【npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141072930277'】方案
问题描述执行npm install的时候报错npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141 ...
- 第1节 MapReduce入门:mapreduce的wordcount程序执行问题
执行时报错: 19/06/03 23:00:41 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs. ...