vijosP1779国王游戏
题解:忽然想起来我好像还没写过高精度除以单精度,于是拿这题练练手。。。没想到1A了。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define maxn (5000+10)
#define for0(i,n) for(int i=0;i<=n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define for2(i,s,t) for(int i=s;i<=t;i++)
#define for3(i,t,s) for(int i=t;i>=s;i--)
#define ll long long
#define mod 10000
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
class bigg
{
public:
int c[maxn],l;
bigg(){memset(c,,sizeof(c));l=;}
bigg operator = (int b)
{
memset(c,,sizeof(c));l=;
while(b)c[++l]=b%mod,b/=mod;
return(*this);
}
bigg operator =(const bigg &b)
{
l=b.l;
for1(i,l)c[i]=b.c[i];
return(*this);
}
bigg operator +(const bigg &b)
{
bigg a;
a.l=max(l,b.l);
for1(i,l)
{
a.c[i]+=a.l+b.l;
a.c[i+]=a.c[i]/mod;
a.c[i]%=mod;
}
if(c[a.l+])a.l++;
return a;
}
bigg operator *(int b)
{
bigg a;a.l=l;
int x=;
for1(i,l)
{
x+=b*c[i];
a.c[i]=x%mod;
x/=mod;
}
while(x)a.c[++a.l]=x%mod,x/=mod;
return a;
}
bigg operator /(int b)
{
bigg a;
int x=;
for3(i,l,)
{
x=x*mod+c[i];
a.c[i]=x/b;
x%=b;
}
a.l=l;
while(!a.c[a.l])a.l--;
return a;
}
void print()
{
printf("%d",c[l]);
for3(i,l-,)printf("%04d",c[i]);printf("\n");
}
};
int n,a[maxn],b[maxn],c[maxn];
inline bool cmp(int x,int y){return a[x]*b[x]<a[y]*b[y];}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read()+;
for1(i,n)a[i]=read(),b[i]=read(),c[i]=i;
sort(c+,c+n+,cmp);
bigg ans;ans=;
for1(i,n-)ans=ans*a[c[i]];
ans=ans/b[c[n]];
ans.print();
return ;
}
vijosP1779国王游戏的更多相关文章
- NOIP2012 国王游戏
2国王游戏 (game.cpp/c/pas) [问题描述] 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数 ...
- 【NOIP 2012 国王游戏】 贪心+高精度
题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排 成一排,国王站在队伍 ...
- Codevs 1198 国王游戏 2012年NOIP全国联赛提高组
1198 国王游戏 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 恰逢 H 国国庆,国王邀 ...
- Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)
Luogu 1080 [NOIP2012]国王游戏 (贪心,高精度) Description 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己 ...
- NOIP国王游戏
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- AC日记——国王游戏 洛谷 P1080
国王游戏 思路: 贪心+高精: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 struct Dat ...
- Luogu P1080国王游戏(贪心)
国王游戏 题目链接:国王游戏 ps:题目数据说明了要写高精度. 这个题的答案是\(a.l * a.r < b.l * b.r\)按照这个进行排序 题解中大部分只是如何证明排序是: \(a.l * ...
- 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)
P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成 ...
- 【题解】洛谷 P1080 国王游戏
目录 题目 思路 \(Code\) 题目 P1080 国王游戏 思路 贪心+高精度.按\(a \times b\)从小到大排序就可以了. \(Code\) #include<bits/stdc+ ...
随机推荐
- DedeCMS文章标题前增加所属栏目名称链接
问题描述:在调用文章标题的时候,我想实现这样的形式:“[国内新闻]站长无忧真的是一个不错的站”,其中“国内新闻”是标题的所属栏目,并且加链接: 解决方法: [field:typelink /]这 ...
- html input[type=file] css样式美化【转藏】
相信做前端的都知道了,input[type=file]和其他输入标签不一样,它的事件必须是在触发自身元素上,而不能是其他元素.所以不能简单的把input隐藏,放个button上去. <a hre ...
- CSS Padding(填充)
CSS Padding(填充)属性定义元素边框与元素内容之间的空间. Padding(填充) 当元素的 Padding(填充)(内边距)被清除时,所"释放"的区域将会受到元素背景颜 ...
- 请描述一下 cookies,sessionStorage 和 localStorage 的区别?
http://handyxuefeng.blog.163.com/blog/static/454521722013111714040259/ http://book.51cto.com/art/201 ...
- session原理及实现集群session的方案原理
对Web服务器进行集群,Session的安全和同步是最大的问题,实现Session同步有很多种方案,常见的可能的方式有: 1.客户端Cookie加密. 用的较少,此处不详述. 2.Session ...
- codevs 4511 信息传递(NOIP2015 day1 T2)
4511 信息传递 NOIP2015 day1 T2 时间限制: 1 s 空间限制: 128000 KB 传送门 题目描述 Description 有个同学(编号为 1 到)正在玩一个信息传递的游戏. ...
- C++的函数重载 转
——每个现象后面都隐藏一个本质,关键在于我们是否去挖掘 写在前面: 函数重载的重要性不言而明,但是你知道C++中函数重载是如何实现的呢(虽然本文谈的是C++中函数重载的实现,但我想其它语言也是类似的) ...
- POJ 2965 The Pilots Brothers' refrigerator 位运算枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 151 ...
- win7 进程kill
文章出处:http://www.cnblogs.com/winstic/,请保留此连接 在使用windows操作时,经常会遇到一些顽固进程大占CPU,很是苦恼:今天就遇到这样的问题,刚写的一个一个分布 ...
- JSON取代XML?--JSON入门指南
定义 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C, C++, C# ...