题目链接:http://codeforces.com/problemset/problem/93/B

B. End of Exams
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams!

Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe, the m friends found n different kinds of milk on the menu, that's why they ordered n bottles — one bottle of each kind. We know that the volume of milk in each bottle equals w.

When the bottles were brought in, they decided to pour all the milk evenly among the m cups, so that each got a cup. As a punishment for not passing the test Igor was appointed the person to pour the milk. He protested that he was afraid to mix something up and suggested to distribute the drink so that the milk from each bottle was in no more than two different cups. His friends agreed but they suddenly faced the following problem — and what is actually the way to do it?

Help them and write the program that will help to distribute the milk among the cups and drink it as quickly as possible!

Note that due to Igor K.'s perfectly accurate eye and unswerving hands, he can pour any fractional amount of milk from any bottle to any cup.

Input

The only input data file contains three integers n, w and m (1 ≤ n ≤ 50, 100 ≤ w ≤ 1000, 2 ≤ m ≤ 50), where n stands for the number of ordered bottles, w stands for the volume of each of them and m stands for the number of friends in the company.

Output

Print on the first line "YES" if it is possible to pour the milk so that the milk from each bottle was in no more than two different cups. If there's no solution, print "NO".

If there is a solution, then print m more lines, where the i-th of them describes the content of the i-th student's cup. The line should consist of one or more pairs that would look like "b v". Each such pair means that v (v > 0) units of milk were poured into the i-th cup from bottle b (1 ≤ b ≤ n). All numbers b on each line should be different.

If there are several variants to solve the problem, print any of them. Print the real numbers with no less than 6 digits after the decimal point.

Examples
Input

Copy

2 500 3

Output

Copy

YES1 333.3333332 333.3333332 166.666667 1 166.666667

Input

Copy

4 100 5

Output

Copy

YES3 20.000000 4 60.0000001 80.0000004 40.000000 2 40.0000003 80.0000002 60.000000 1 20.000000

Input

Copy

4 100 7

Output

Copy

NO

Input

Copy

5 500 2

Output

Copy

YES4 250.000000 5 500.000000 2 500.0000003 500.000000 1 500.000000 4 250.000000

题目大意:输入n,w,m 分别代表n杯不同的饮料,每杯饮料有w体积,要平均分为m杯思路:这题A出来感觉非常不简单,一天就做了这一道题。。。  其实这题要懂的就是如何贪心,然后如何存数据答案,还有一个很重要的就是double的精度问题,控制不好就别想过了贪心思想是: 每次都使得当前用的饮料尽可能的多,如果用了两次都没有用完的话,那就显然是“NO”了,贪心思想很简单。然后关于存储数据的:因为我们并不知道装满一杯要多少种饮料,所以这个就必须要用动态存储了,这就需要用到vector,我们要存储的有第几杯,用了哪种饮料,用了多少,所以要三个变量来存储。  学了一下如果用vector来存储三个变量,就是再用一个pair,具体怎么用在代码中可以看到double精度的控制:这题本来自己感觉是没有问题的,然后提交,wa在第十个吧,忘记了,然后试了数据,发现结果跟自己想的不一样,后来改代码,把过程中的结果输出来,发现在运行过程中double 保留的是三位小数,但是相减却又保留的是六位小数,比如一个是333.333,1000和它相减则会得到666.666667,,但是下一次和666.667比较,如果我们简单的比较二者是否相等的话,显然是不相等的,但是二者实际上是相等的,所以要二者相减判断差值是否在误差之外就行了。看代码
#include<iostream>
#include<string.h>
#include<map>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<ctype.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
const int maxn=1e3+10;
const int maxk=5e3+10;
const int maxx=1e4+10;
const ll maxe=1000+10;
#define INF 0x3f3f3f3f3f3f
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
typedef pair<int,double> p;
int main()
{//vector<pair<int,double> > ans[100];vector<p>ans[100];p fun;int n,w,m;cin>>n>>w>>m;if(m>n*2) cout<<"NO"<<endl;//n瓶饮料最多能分出2*n杯饮料,所以大于它直接NOelse{int cnt=1,sum1=1,sum3=0;//cnt代表第几瓶,sum1代表第几个人,sum3判断是否用了两次以上double ave=1.0*n*w/m;double sum=ave,sum2=w;//补满一瓶还需的容量,一瓶还剩多少while(cnt<=n&&sum1<=m)//
        {if(fabs(sum-sum2)<1e-6)//精度判断,一定要放在最前面,不然会判断别的,也就wa了
            {//cout<<"2"<<endl;fun.first=cnt;fun.second=sum2;ans[sum1].push_back(fun);//ans[sum1].push_back({cnt,sum2});sum3++;if(sum3>2){cout<<"NO"<<endl;return 0;}//ans[cnt].insert(n);//ans.insert(cnt,n);sum3=0;sum2=w;sum=ave;cnt++;sum1++;//cout<<cnt<<" "<<sum<<" "<<sum2<<endl;
            }else if(sum>sum2){// cout<<"1"<<endl;fun.first=cnt;fun.second=sum2;ans[sum1].push_back(fun);//ans[sum1].push_back({cnt,sum2});
sum3++;if(sum3>2){cout<<"NO"<<endl;return 0;}sum3=0;sum-=sum2;sum2=w;cnt++;}//else if(sum==sum2)else{//cout<<"3"<<endl;//printf("%.3lf %.6lf\n",sum,sum2);fun.first=cnt;fun.second=sum;ans[sum1].push_back(fun);//ans[sum1].push_back({cnt,sum});sum2=sum2-sum;if(sum2==0.000000) cout<<"sss"<<endl;sum=ave;sum3++;sum1++;}if(sum3>2){cout<<"NO"<<endl;return 0;}}cout<<"YES"<<endl;for(int i=1;i<=m;i++){for(int j=0;j<ans[i].size();j++){printf("%d %.6lf ",ans[i][j].first,ans[i][j].second);//cout<<ans[i][j].first<<" "<<ans[i][j].second;
            }cout<<endl;}}return 0;
}

转载于:https://www.cnblogs.com/caijiaming/p/9450294.html

CodeForces - 93B(贪心+vectorpairint,double +double 的精度操作相关推荐

  1. [ JAVA编程 ] double类型计算精度丢失问题及解决方法

    [ JAVA编程 ] double类型计算精度丢失问题及解决方法 参考文章: (1)[ JAVA编程 ] double类型计算精度丢失问题及解决方法 (2)https://www.cnblogs.co ...

  2. (金融入门知识点)Double类型丢失精度

    Double计算精度丢失原因:Double计算精度丢失(金融入门知识点)__yosemite的博客-CSDN博客_double精度丢失 Double计算精度丢失解决办法:Double类型丢失精度的两种 ...

  3. double java 精度丢失_java中double和float精度丢失问题及解决方法

    在讨论两位double数0.2和0.3相加时,毫无疑问他们相加的结果是0.5.但是问题总是如此吗? 下面我们让下面两个doubles数相加,然后看看输出结果: @Test public void te ...

  4. Java double和float精度损失问题

    问题 一般,我们会用float和double来存储有小数的数据,可能还会用两个浮点型数据进行计算,在某些情况下,float和double会出现精度损失,导致存储的数据或者计算结果出现误差. 举个例子 ...

  5. 【c++】double转int精度丢失问题

    #include <iostream>int main() {double a = 74.49;int b = a * 100;std::cout << "a: &q ...

  6. include/caffe/common.cuh(9): error: function atomicAdd(double *, double) has already been defined

    编译caffe时出现: include/caffe/common.cuh(9): error: function "atomicAdd(double *, double)" has ...

  7. 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法

    原代码: Assert.assertEquals(29.9, discountObj.getPrice()); JUnit 4.13.2 警告:'assertEquals(double, double ...

  8. Java中如何解决double和float精度不准的问题

    我们知道浮点数是无法在计算机中准确表示的,例如0.1在计算机中只是表示成了一个近似值,因此,对付点数的运算时结果具有不可预知性. 在进行数字运算时,如果有double或float类型的浮点数参与计算, ...

  9. java long double精度丢失_long long类型转double类型部分精度丢失问题

    我最近做了一道题,一个64位(unsigned __int64)范围内的数输出其除以1000的值,并按四舍五入保留小数点后三位. 我刚开始直接写WA,结果发现当数比较大的时候,结果后几位精度总会丢失, ...

最新文章

  1. 调试寄存器(debug registers, DRx)理论及实践
  2. JavaScript之三:jQuery插件开发(一)
  3. 【数据结构与算法】之单向循环链表的创建/遍历/插⼊/查找/删除算法实现
  4. 北京供销大数据集团发布SinoBBD Cloud 一体化推动产业云发展
  5. 权限组件(6):权限分配的角色管理
  6. 看门狗性能软件测试,《看门狗:军团》PC版性能测试 不建议光追,优化极差
  7. github比sourceforge好在哪?
  8. particle filtering---粒子滤波(讲的很通俗易懂)
  9. Atitit 个人 企业 政府 等组织 财政收入分类与提升途径attilax总结 1.1. 国家财政收入分类 1 1.2. 企业收入分类 1 1.3. 个人收入分类 1 1.1.国家财政收入分类
  10. 图片处理view - 成图,
  11. 麒麟信安总裁刘文清:携手 openEuler,共推操作系统产业新发展
  12. VAE 中后验坍塌问题
  13. 【论文导读】Continuity Scaling: A Rigorous Framework for Detecting andQuantifying Causality Accurately
  14. wpf中使用ListView
  15. jboot 增加llog4j日志
  16. 自动祝福程序(定时发送消息)
  17. JS上传文件(base64字符串和二进制文件流)
  18. Docker in Docker dind
  19. Kanzi: kanzi基础 : 使用预设件
  20. android10.0 bootanimation系统高仿Iphone苹果开机动画

热门文章

  1. 解决IntelliJ IDEA控制台乱码问题[包含程序运行时的log4j日志以及tomcat日志乱码]
  2. linux的8小时差问题解决
  3. 内容推荐策略产品经理的方法和实践
  4. 【白皮书分享】2021内容营销白皮书.pdf(附下载链接)
  5. 【干货】从0到1打造企业数字化运营闭环白皮书.pdf(附下载链接)
  6. Facebook 面向个性化推荐系统的深度学习推荐模型
  7. 来鹅厂干大事!腾讯广告技术类岗位高能来袭~
  8. php写进度条原理,php实现进度条原理
  9. 使用VScode + PicGo 写markdown 以及github图片加载不出的问题
  10. 交叉熵的本质是极大似然估计