描述

恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏。首先,他让每个大臣在左、右手上面分别写下一个整数,国王自己也在左、右手上各写一个整数。然后,让这n位大臣排成一排,国王站在队伍的最前面。排好队后,所有的大臣都会获得国王奖赏的若干金币,每位大臣获得的金币数分别是:排在该大臣前面的所有人的左手上的数的乘积除以他自己右手上的数,然后向下取整得到的结果。 
国王不希望某一个大臣获得特别多的奖赏,所以他想请你帮他重新安排一下队伍的顺序,使得获得奖赏最多的大臣,所获奖赏尽可能的少。注意,国王的位置始终在队伍的最前面。

格式

输入格式

第一行包含一个整数n,表示大臣的人数。 
第二行包含两个整数a和b,之间用一个空格隔开,分别表示国王左手和右手上的整数。接下来n行,每行包含两个整数a和b,之间用一个空格隔开,分别表示每个大臣左手和右手上的整数。

输出格式

输出只有一行,包含一个整数,表示重新排列后的队伍中获奖赏最多的大臣所获得的金币数。

输入:

3
1 1
2 3
7 4
4 6

输出:

2

思路:将大臣按左右手整数之积从小到大排序,为解决溢出问题,采用C++大数。

#include <iostream>
#include <iomanip>
#include <string.h>
#include <algorithm>
using namespace std;
const int MAXN=;
const int BASE=;
const int LEN=;
struct BigInt{
int e[MAXN],len;
BigInt()
{
memset(e,,sizeof(e));
len=;
}
void set(int x)
{
memset(e,,sizeof(e));
len=;
while(x>)
{
e[len++]=x%BASE;
x/=BASE;
}
}
bool operator>(const BigInt &b)
{
if(len>b.len)
{
return true;
}
else if(len==b.len)
{
for(int i=len-;i>=;i--)
{
if(e[i]>b.e[i]) return true;
else if(e[i]<b.e[i]) return false;
else ;
}
return false;
}
else
{
return false;
}
}
BigInt operator*(const BigInt &b)
{
BigInt res;
for(int i=;i<len;i++)
{
int up=;
for(int j=;j<b.len;j++)
{
int z=e[i]*b.e[j]+up+res.e[i+j];
res.e[i+j]=z%BASE;
up=z/BASE;
}
if(up!=) res.e[i+b.len]=up;
}
res.len=len+b.len;
while(res.len>&&res.e[res.len-]==) res.len--;
return res;
}
BigInt operator/(const int &b)
{
BigInt res=*this;
int carry=;
for(int i=len-;i>=;i--)
{
res.e[i]+=carry*BASE;
carry=res.e[i]%b;
res.e[i]/=b;
}
while(res.len>&&res.e[res.len-]==) res.len--;
return res;
}
friend ostream &operator<<(ostream &out,const BigInt &b)
{
out<<b.e[b.len-];
for(int i=b.len-;i>=;i--)
{
out<<setw(LEN)<<setfill('')<<b.e[i];
}
out<<endl;
return out;
}
};
struct Node{
int x,y;
}mon[MAXN];
bool comp(const Node &a,const Node &b)
{
return a.x*a.y < b.x*b.y;
}
int n,kl,kr;
int main()
{
cin>>n;
cin>>kl>>kr;
for(int i=;i<n;i++)
{
cin>>mon[i].x>>mon[i].y;
}
sort(mon,mon+n,comp);
BigInt res;
res.set();
BigInt mul;
mul.set(kl);
for(int i=;i<n;i++)
{
BigInt tmp;
tmp=mul/mon[i].y;
if(tmp>res) res=tmp;
BigInt b;
b.set(mon[i].x);
mul=mul*b;
}
cout<<res<<endl;
return ;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct BigInt{
static const int SIZE = ;
int e[SIZE], len;
BigInt()
{
len = ;
memset(e, , sizeof(e));
}
void reset(int x)
{
while(x > )
{
e[len++] = x % SIZE;
x /= SIZE;
}
while(len > && e[len-] == ) len--;
}
bool operator>(const BigInt& b)
{
if(len > b.len) return true;
else if(len < b.len) return false;
else
{
for(int i = len - ; i >= ; i--)
{
if(e[i] == b.e[i]) continue;
else if(e[i] > b.e[i]) return true;
else return false;
}
}
return false;
}
BigInt operator*(const BigInt& b)
{
BigInt ret;
for(int i = ; i < len; i++)
{
int up = ;
for(int j = ; j < b.len; j++)
{
int z = e[i] * b.e[j] + ret.e[i+j] + up;
ret.e[i+j] = z % SIZE;
up = z / SIZE;
}
if(up != )
{
ret.e[i + b.len] = up;
}
}
ret.len = len + b.len;
while(ret.len > && ret.e[ret.len-] == ) ret.len--;
return ret;
}
BigInt operator/(int b)
{
BigInt ret = *this;
int carry = ;
for(int i = len - ; i >=; i--)
{
ret.e[i] += carry * SIZE;
carry = ret.e[i] % b;
ret.e[i] /= b;
}
while(ret.len > && ret.e[ret.len - ] == ) ret.len--;
return ret;
}
void print()
{
printf("%d", e[len-]);
for(int i = len - ; i >= ; i--)
{
printf("%04d", e[i]);
}
printf("\n");
}
};
const int MAXN = ;
struct Node{
int x, y;
}nod[MAXN];
int n, kl, kr;
bool comp(Node a, Node b)
{
return a.x * a.y < b.x * b.y;
}
int main()
{
scanf("%d %d %d", &n, &kl, &kr);
for(int i = ; i < n; i++)
{
scanf("%d %d", &nod[i].x, &nod[i].y);
}
sort(nod, nod + n, comp);
BigInt res, mul;
res.reset(kl / nod[].y);
mul.reset(kl);
for(int i = ; i < n; i++)
{
BigInt b;
b.reset(nod[i-].x);
mul = mul * b;
BigInt score = mul / nod[i].y;
if(score > res)
{
res = score;
}
}
res.print();
return ;
}

vijos1779国王游戏的更多相关文章

  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. nginx学习之详细安装篇(二)

    1. 选择稳定版还是主线版 主线版:包含最新的功能和bug修复,但该版本可能会含有一些属于实验性的模块,同时可能会有新的bug,所以如果只是做测试使用,可以使用主线版. 稳定版:不包含最新的功能,但修 ...

  2. php, tp5, 选中导航菜单

    1. 首先定义一个函数: function nav_select($navindex){ $nav_arr = [ 1 => ['index',], 2 => ['mei',], 3 =& ...

  3. Android笔记之自定义的RadioGroup、RadioButton,以及View实例状态的保存与恢复

    效果图 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  4. zip filter map 列表生成器

    map map(function, list): 就是对list 中的每一个元素都调用function函数进行处理,返回一个map的对象 list一下就可以生成一个列表 或者for循环该对象就可以输出 ...

  5. CXF生成client注意事项

    1. 在使用wsdl2java命令生成client文件时在Service的Java文件中面出现super构造错误,这是因为jax-ws2.2规约与java6冲突  故须要减少jax-ws规约版本号. ...

  6. JVM虚拟机参数

    追踪参数: 打印GC简要信息 -XX:+PrintGC 打印GC详细信息 -XX:+PrintGCDetails 打印CG发生的时间戳 -XX:+PrintGCTimeStamps 指定GC log的 ...

  7. HDU - 1033 Edge 【模拟】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1033 题意 给定一个起始点 300 420 走的第一步是 310 420 下面的每一步 都由 输入决定 ...

  8. Monkey for Mac 环境配置

    Monkey for Mac环境配置步骤 java环境配置, 直接去官网找对应jdk就可以了 Android  AdtBundle环境配置 1) 下载地址: http://www.jianshu.co ...

  9. /dev/sda

    /dev/sda这是Linux系统下的设备文件,类似Windows系统上面的本地磁盘.U盘.光驱等设备.Linux系统访问设备文件需要mount命令挂载映射成文件,查看: 1.建一个目录(挂载磁盘分区 ...

  10. Spark- SparkStreaming可更新状态的实例

    Producer package zx.zx.sparkkafka import java.util.Properties import kafka.producer.{KeyedMessage, P ...