POJ 3063 Sherlock Holmes
来源:互联网 发布:php最简单代码 编辑:程序博客网 时间:2024/05/03 05:34
Sherlock Holmes
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 662 Accepted: 213
Description
Sherlock Holmes, the well known detective, must solve a puzzling situation. He has n boxes B1, B2, .., Bn , where n is even, each containing m balls. The balls are white and black. Let Bi = (Wi, Bi) denote a box with Wi white balls and Bi black balls. He must partition the boxes into two sets, each consisting of n/2 boxes, such that either the white balls or the black balls hold amajority in both sets. If there is such a majority, let m1 and m2 denote the percentage of the majority balls in each set. Holmes must find very quickly the maximum possible value of min(m1, m2). Can you help Holmes?
Input
There are several testcases. Each data set in the file stands for a particular set of boxes. A data set starts with the number n (n < 10000) of boxes. Follows the number m (m < 10000) of balls, and for each box the number (< 10000) of white and black balls in this specific order. White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
Output
For each set of data the program prints the result to the standard output from the beginning of a line. The program prints the color (W or B) of the balls that hold the majority followed by the maximum value - if there is such a majority, or "No solution" (without quotes) if no majority can be obtained. An input/output sample is in the table below. There is a single data set that contains 4 boxes each containing 30 balls. The first box, for example, contains 17 white balls and 13 black balls. There is only one possible partition of the boxes (B1, B4), (B2, B3), the white balls holding majority. The result for the data set is the identifier W and the maximum value.
Sample Input
43017 1312 1820 1014 16
Sample Output
W 51.67
Source
Southeastern Europe 2006
一开始给的中文题目 居然没有说平均分成两组。。。
只能rand()%2分组+卡时 Wa了3个点
后来平均分后 随机交换两组中的两个+卡次数
写得挺丑的。。。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<iomanip>#include<ctime>using namespace std;struct self{int x,y,side;}s[10001];int m,n,a,b,c;double ans,z;int side=-1;int baizong,heizong,num;int l[2],r[2];int x,y;void tongji(){ if(l[0]>r[0]&&l[1]>r[1]) { double k=min((double)l[0]/(m/2*n),(double)l[1]/(m/2*n)); if(k>ans) { ans=k; side=0; } } if(l[0]<r[0]&&l[1]<r[1]) { double k=min((double)r[0]/(m/2*n),(double)r[1]/(m/2*n)); if(k>ans) { ans=k; side=1; } }}void exchange(int x,int y){ l[0]-=s[x].x; r[0]-=s[x].y; l[1]+=s[x].x; r[1]+=s[x].y; s[x].side=1; l[1]-=s[y].x; r[1]-=s[y].y; l[0]+=s[y].x; r[0]+=s[y].y; s[y].side=0; }int main(){ srand(time(NULL)); while(scanf("%d",&m)==1) { scanf("%d",&n); num=0; ans=0; baizong=0; heizong=0; side=-1; l[0]=r[0]=l[1]=r[1]=0; for(a=1;a<=m;a++) { scanf("%d%d",&s[a].x,&s[a].y); baizong+=s[a].x; heizong+=s[a].y; } if(baizong>heizong)side=0; else side=1; for(a=1;a<=m/2;a++) { s[a].side=0; l[0]+=s[a].x; r[0]+=s[a].y; } for(a=m/2+1;a<=m;a++) { s[a].side=1; l[1]+=s[a].x; r[1]+=s[a].y; } while(num<=50000) { num++; x=rand()%m+1; while(s[x].side!=0)x=rand()%m+1; y=rand()%m+1; while(s[y].side!=1)y=rand()%m+1; z=ans; exchange(x,y); tongji(); if(ans>z)if(rand()%1000+1<=50)exchange(y,x);else; else if(rand()%1000+1>=50)exchange(y,x); } if(ans==0) cout<<"No solution"<<'\n'; else if(side==0) cout<<"W "; else cout<<"B "; if(ans!=0)cout<<fixed<<setprecision(2)<<ans*100<<'\n'; } return 0;}
- POJ 3063 Sherlock Holmes
- POJ 3063 Sherlock Holmes 随机化
- POJ 3063 Sherlock Holmes 笔记
- holmes查bug过程总结
- 【题解】codeforces776E The Holmes Children
- 英文学习Holmes Day1~6.
- Hackerrank Sherlock and Squares
- woj1208 Sherlock's Code
- Codechef:Sherlock and Inversions
- Sherlock and Cost
- Sherlock and his girlfriend
- Sherlock and Watson
- Sherlock and his girlfriend
- WOJ1208-Sherlock's Code
- Hackerrank Sherlock and The Beast
- B. Sherlock and his girlfriend
- B. Sherlock and his girlfriend
- B. Sherlock and his girlfriend
- DK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用简介
- TCP/IP 连接三次握手与释放四次握手
- 安卓编程常见错误记录
- JoystickMouse
- 要求把地板上的花去掉
- POJ 3063 Sherlock Holmes
- Android实时监控项目第四篇:后台线程发送预览帧视频数据
- UVA10763
- hive 使用相关问题
- Android开发教程:手机震动控制浅析
- java concurrency in practice读书笔记----第三章
- update 一条语句的来龙去脉!
- mini2440 jlink烧写总是出现错误解决方法
- eclipse 下一些常用到插件到官方地址