题目: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. html响应式布局,css响应式布局,响应式布局入门

    html响应式布局,css响应式布局,响应式布局入门 >>>>>>>>>>>>>>>>>>& ...

  2. WPF中窗口控件的跨线程调用

    在WinForm中,我们要跨线程访问窗口控件,只需要设置属性CheckForIllegalCrossThreadCalls = false;即可. 在WPF中要麻烦一下,同样的不允许跨线程访问,因为没 ...

  3. Android 输入法键盘和activity页面遮挡问题解决

    本文主要介绍Android中如何解决输入法键盘和activity页面遮挡的问题. 总结: 不希望遮挡设置activity属性android:windowSoftInputMode="adju ...

  4. 跟着老男孩一步步学习Shell高级编程实战

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://oldboy.blog.51cto.com/2561410/1264627 本sh ...

  5. [Twisted] transport

    transport代表网络上两个节点的连接.它描述了连接的具体细节,如TCP还是UDP. transports实现了ITransport接口,包含以下方法 write:以非阻塞的方式向连接写数据. w ...

  6. C#字符串颠倒输出

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  7. 需要 了解 j2ee 框架

    只要你是用java来做WEB应用,绝对少不了使用j2ee框架,目前流行的有 l\5qa_{z   Y(/VW&K&:   )zt*am;   1)struts   2)spring   ...

  8. HTML5 程序设计笔记(二)

    Canvas API 1.HTML5 Canvas 概述 1.1 历史 Canvas的概念最初是由苹果公司提出的,用于在Mac OS X WebKit中创建控制板部件(dashboard widget ...

  9. 【原创】Android 对话框的使用

    对话框即Dialog .google的官方解释:A dialog is usually a small window that appears in front of the current Acti ...

  10. 关于js的callback回调函数的理解

    回调函数的处理逻辑理解:所谓的回调函数处理逻辑,其实就是先将回调函数的代码 冻结(或者理解为闲置),接着将这个回调函数的代码放到回调函数管理器的队列里面. 待回调函数被触发调用的时候,对应的回调函数的 ...