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+ ...
随机推荐
- JS获取URL的参数
function request(paras) { var url = location.href; , url.length).split("&"); var paraO ...
- build/core/config.mk
# 如果定义了ANDROID_BUILD_SHELL,则ANDROID_BUILD_SHELL # 否则使用默认的/bin/bash ifdef ANDROID_BUILD_SHELL SHELL : ...
- mRemote配置
配置完mRemote后 备份C:\Users\Administrator\AppData\Local\Felix_Deimel\mRemote\confCons.xml文件 覆盖到其他电脑可以直接使用
- Unity3D中读取CSV文件
直接上代码 Part1: using UnityEngine; using System.IO; using System.Collections.Generic; public class CSV ...
- Sublime Text使用心得(一)
以前写web前端样式都是用eclipse.myeclispe这些IDE开发工具,现在想纯粹的写点HTML的东西,一心想找一个轻量的编辑器,这样能够随手打开编写,方便平时业余学习.网上搜罗了一堆编辑器, ...
- arcgis engine - 添加图例,指北针.
esri帮助提供了使用比例尺的方法: Working with map surrounds 主要代码为: public void AddMapSurround(IPageLayout pageLayo ...
- C#常用的关键字
常用关键字有 this 1)当前类的对象 2)调用自己的构造函数 new base virtual interface abstract override parttial sealed return ...
- .NET开源工程推荐(Accord,AForge,Emgu CV)
本人用C#开发了一些项目,下面的开源工程给了我很大的帮助——详细的源代码介绍加丰富的实例运用,是非常不错的学习资源,分享给大家,同时附上我的相关开发项目. Accord.NET The ...
- ecshop---京东手机模板js的eval产生冲突的解决方法。
今天弄ecshop手机模板的时候,发现首页的广告图出不来,js报错
- js键盘控制div移动,解决停顿问题
问题版本代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <html> &l ...