题目:https://vijos.org/p/1779

题解:忽然想起来我好像还没写过高精度除以单精度,于是拿这题练练手。。。没想到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国王游戏的更多相关文章

  1. NOIP2012 国王游戏

    2国王游戏 (game.cpp/c/pas) [问题描述] 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数 ...

  2. 【NOIP 2012 国王游戏】 贪心+高精度

    题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排 成一排,国王站在队伍 ...

  3. Codevs 1198 国王游戏 2012年NOIP全国联赛提高组

    1198 国王游戏 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 恰逢 H 国国庆,国王邀 ...

  4. Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)

    Luogu 1080 [NOIP2012]国王游戏 (贪心,高精度) Description 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己 ...

  5. NOIP国王游戏

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  6. AC日记——国王游戏 洛谷 P1080

    国王游戏 思路: 贪心+高精: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 struct Dat ...

  7. Luogu P1080国王游戏(贪心)

    国王游戏 题目链接:国王游戏 ps:题目数据说明了要写高精度. 这个题的答案是\(a.l * a.r < b.l * b.r\)按照这个进行排序 题解中大部分只是如何证明排序是: \(a.l * ...

  8. 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)

    P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成 ...

  9. 【题解】洛谷 P1080 国王游戏

    目录 题目 思路 \(Code\) 题目 P1080 国王游戏 思路 贪心+高精度.按\(a \times b\)从小到大排序就可以了. \(Code\) #include<bits/stdc+ ...

随机推荐

  1. 微信45028错误,微信has no masssend quota hint错误

    微信45028,微信has no masssend quota hint 微信测试账号群发出现45028,has no masssend quota hint错误 >>>>&g ...

  2. 2015前端各大框架比较(angular,vue,react,ant)

    前端流行框架大比拼 angular vue react ant-design angularjs angular是个MVVM的框架.针对的是MVVM这整个事.angular的最主要的场景就是单页应用, ...

  3. IE8下网页中的视频会遮挡住顶层DIV的解决办法

    在IE8浏览器下,发现网页中的视频会遮挡住本来固定在最顶层的DIV.即便使用z-index也无法解决.但是其他浏览器是正常的. 解决的办法很简单,就是在调用flash视频播放器的时候,加上一个参数“o ...

  4. CI框架篇之视图篇--载入(1)

    创建视图 创建视图文件很简单,只需要建立后缀名为‘.php’的文件, 然后保存文件到 application/views/ 文件夹即可 当然,随着工程的大小,你有必要对很多的视图根据控制器进行归类, ...

  5. sql中对查询出来的数据进行分页

    当sql中存储的数据量比较大时,在web中 数据显示时都会对数据进行分页,分页不会在客户端进行分页,而是在数据库查询过程中进行了分页. sql代码: DECLARE @pageindex INT; - ...

  6. 自动化构建jenkins配置

    1.安装jdk7+tomcat7 2.下载msi安装文件(我是win7上安装,下载地址 http://Jenkins-ci.org/),文件安装路径选择\tomcat\webapps. 3.安装成功之 ...

  7. swift 截取字符串

  8. CorAnimation7-高效绘图、图像IO以及图层性能

    高效绘图 软件绘图 术语绘图通常在Core Animation的上下文中指代软件绘图(意即:不由GPU协助的绘图).在iOS中,软件绘图通常是由Core Graphics框架完成来完成.但是,在一些必 ...

  9. c#equals相关

    1.==是直接比较值类型的值或引用类型的引用地址,但==不能用于struct,struct只能用equals来比较.==一般情况下与object.equals得到的结果是相等的. 2.Referenc ...

  10. 利用SpringMVC参数绑定实现动态插入数据

    javabean代码:public class User { private String firstName; private String lastName; public String getF ...