poj 3940 Grey Area 浮点输出控制

水题,直接贴代码,注意几种控制浮点输出的方法:e格式,以指数形式输出实数。g格式:自动选f格式或e格式中较短的一种输出,且不输出无意义的零。

代码:

//poj 3940
//sep9
#include <iostream>
using namespace std;
const int maxL=64;
int cnt[maxL+10];
double color[maxL];
double area[maxL];

int main()
{
	double p=0.10000;
	int n,w;
	while(scanf("%d%d",&n,&w)==2&&(n+w)){
		memset(cnt,0,sizeof(cnt));
		int max_cnt=-1;
		for(int i=0;i<n;++i){
			int x;
			scanf("%d",&x);
			++cnt[x/w];
			max_cnt=max(max_cnt,cnt[x/w]);
		}
		int L;
		for(L=maxL;L>=0;--L)
			if(cnt[L])
				break;
		for(int i=0;i<L;++i)
			color[i]=(L-i)*1.0/L;
		for(int i=0;i<L;++i)
			area[i]=cnt[i]*1.0/max_cnt;
		double ans=0.0;
		for(int i=0;i<L;++i)
			ans+=color[i]*area[i];
		printf("%.10lg\n",ans+0.01);
	}
	return 0;
}
 
时间: 2024-08-24 21:46:10

poj 3940 Grey Area 浮点输出控制的相关文章

POJ 1265:Area

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4725   Accepted: 2135 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

SD--如何在输出控制中增加自定义字段

在sap的输出控制中,我们有时需要增加系统未定义的字段作为条件表的字段,为了实现该需求我们就需要修改增强. 输出控制用到的通讯结构 KOMKBK1 (Output Determination Communication Area CAS Appl. K1) KOMKBV1 (Output Determination Communication Area Header Appl. V1) KOMKBV2 (Output Determination Communication Area Header

Grey Area(数学统计题)

Grey Area Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Special Judge Submit Status PID: 1083 Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the world eve

cout输出控制——位数和精度控制

刷到一道需要控制输出精度和位数的题目 刚开始以为单纯使用 iomanip 函数库里的 setprecision 就可以,但 OJ 给我判了答案错误,后来一想这样输出并不能限制位数只能限制有效位数. 比如说 0.000101000110 用 setprecision(4) 答案是 0.000101 这里甚至把最后一位的有效数字 0 省略了!! 后来了解到 fixed 关键字 那么在这里若要控制小数点后 N 位 只要写成 cout << fixed << setprecision(N)

[ZigBee] 3、ZigBee基础实验——GPIO输出控制实验-控制Led亮灭

1.CC2530的IO口概述 CC2530芯片有21 个数字输入/输出引脚,可以配置为通用数字I/O 或外设I/O 信号,配置为连接到ADC.定时器或USART外设.这些I/O 口的用途可以通过一系列寄存器配置,由用户软件加以实现. I/O 端口具备如下重要特性:    ?? 21 个数字I/O 引脚 ?? 可以配置为通用I/O 或外部设备I/O ?? 输入口具备上拉或下拉能力 ?? 具有外部中断能力. 21 个I/O 引脚都可以用作于外部中断源输入口.因此如果需要外部设备可以产生中断.外部中断

C++ 控制台代码输出控制

在C++控制台应用程序中可以控制控制台输出的字体颜色和 接受任意按键退出 #ifndef CONSOLE_UTILS_H #define CONSOLE_UTILS_H #include <windows.h> #include <conio.h> #include <iostream> //default text colors can be found in wincon.h inline void SetTextColor(WORD colors) { HANDL

poj 2337 之 有向图 欧拉路径输出

/* poj 2337 之 有向图 欧拉路径输出  每个单词看作一条有向边,顶点即为单词首尾字母,然后求欧拉路径即可. 1)为保证字典序,先对单词按字典序排序 2)深搜,输出单词序列 */ 1 #include <iostream> 2 #include <fstream> 3 #include <sstream> 4 #include <cstdlib> 5 #include <cstdio> 6 #include <cstddef>

poj 1815 Friendship 最小割输出最小方案

这题卡了好久啊,最小割模型很容易想,拆点就行.就像poj的Thieves一样 每个点 a拆成 a->a',容量为1. 其他相连的点 a'->b ,容量为INF 源连接s',t连接汇 问题在于输出最小的割集 更好的方法我还不会,只能枚举. 这里基于贪心的思想,从小到大删边, 若删除i->i',会使得最小割变小,则输出i,并且i->i'这条边不要恢复 若最小割不变,则恢复这条边,继续枚举. 一开始就是因为恢复了要割去的边,无限WA. #include<cstdio> #in

unity中Debug输出控制

1 需求: (1)选择在界面.console中输出,并且能够设置保存到文档 (2)控制debug是否输出,可以在debug模式下输出,release模式下不输出 2 参考: 谢谢雨松同学的博客:http://www.xuanyusong.com/archives/2782 , 雨松飞天般的想法实在太奇妙了,虽然我现在还没有理解里面的原理.雨松把debug类常用函数封装在debuger类中,然后通过封装DLL的方式解决Log输出后的定位的问题. 3 方案:   3.1  Dll生成 Debug输出