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+ ...
随机推荐
- Razor的理解
[原创]Razor非常智能非常实用,不了解的人可能会觉得有没有都无所谓,其实不然,起初对Razor不是太了解,现在想想Razor就是来标示出C#语法的,但是HTML和C#混合输出时到底@这个小老鼠到底 ...
- bootstrap 模态框关闭状态怎么获取
比如现在有个场景,一个事件 需要在模态框关闭之后再执行自己的逻辑,先上图: 参考官网说明:http://v3.bootcss.com/javascript/#modals-events //每次关闭模 ...
- Tomcat - java.lang.UnsupportedClassVersionError:Unsupported major.minor version 51.0 (unable to load class com.microsoft.sqlserver.jdbc.SQLS
今天使用Tomcat连接sql Server 2008 enterprise的时候,报错: HTTP Status 500 - Servlet execution threw an exception ...
- .NET下的加密解密大全(2):对称加密
本博文列出了.NET下常用的对称加密算法,并将它们制作成小DEMO,希望能对大家有所帮助. 公共代码[csharp]static byte[] CreateKey(int num) { byt ...
- CALayer 认识
一篇很好的讲述calayer的博客 http://www.cnblogs.com/kenshincui/p/3972100.html
- jQuery 杂项方法
jQuery 杂项方法 方法 描述 data() 向被选元素附加数据,或者从被选元素获取数据 each() 为每个匹配元素执行函数 get() 获取由选择器指定的 DOM 元素 index() 从匹配 ...
- Memento 模式
Memento 模式的关键就是要在不破坏封装行的前提下,捕获并保存一个类的内部状态,这样就可以利用该保存的状态实施恢复操作. /////////Originator.h//////////////// ...
- [LeetCode OJ] Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- angularjs应用骨架
使用典型的类库时,你可以选择并使用你所喜欢的功能:而对于angularjs框架来说,必须把它看成一个完整的套件来使用,框架中的所有的东西都包含在里面,接下来将会介绍angular的基础模块,这样你就可 ...
- Photon引擎开发实战(1)——Photon 简介
Photon简介 Photon是一套使用广泛的socket server引擎,服务端底层C++编写,客户端C#编写,跨多平台,收费,效率可观的一款引擎.实用上前有九城游戏(原魔兽世界代理),现在笔者发 ...