luoguP1080 国王游戏 题解(NOIP2012)(贪心+高精)
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define il inline
#define rg register
#define ll long long
#define N 10001
#define inf 1000000010
using namespace std;
int n,a,b;
struct T{
int le,ri;
}h[N];
ll now[N],ans[N],zs[N];
int len1,alen,flag;
il void re(rg int &x);
int cmp(const T &x,const T &y);
void solve(rg int k);
void add(rg int k);
int main()
{
re(n),re(a),re(b);
for(rg int i=;i<=n;++i)
re(h[i].le),re(h[i].ri);
sort(h+,h+n+,cmp);
while(a)
now[++len1]=(a%),a/=;
for(rg int i=;i<=n;++i)
solve(i),add(i);
for(rg int i=len1;i>=;--i){
if((!flag)&&(!ans[i]))continue;
cout<<ans[i];
flag=;
}
return ;
} il void re(rg int &x){
rg int res=,w=;char c=getchar();
while((c<''||c>'')&&c!='-')c=getchar();
if(c=='-')w=-,c=getchar();
while(c>=''&&c<='')res=(res<<)+(res<<)+c-'',c=getchar();
x=w*res;
}
int cmp(const T &x,const T &y){
return (x.le*x.ri)<(y.le*y.ri);
}
void solve(rg int k){
memset(zs,,sizeof(zs));
rg int c=h[k].ri,p=;
for(rg int i=len1;i>=;--i){
p=p*+now[i];
zs[i]=p/c,p%=c;
} for(rg int i=len1;i>=;--i){
if(ans[i]==zs[i])continue;
if(ans[i]>zs[i])break;
memcpy(ans,zs,sizeof(zs));
break;
}
}//除以自己右手上的值统计
void add(rg int k){
rg int c=h[k].le;
for(rg int i=;i<=len1;++i)
now[i]*=c;
for(rg int i=;i<=len1;++i){
if(now[i]>=){
rg int w=i;
while(now[w]>=){
now[w+]+=now[w]/,now[w]%=,w++;
if(w>len1)len1=w;
}
}
}
while(now[len1+]>=)
now[len1+]=(now[len1]/),now[len1]%=,len1++;
}
luoguP1080 国王游戏 题解(NOIP2012)(贪心+高精)的更多相关文章
- [贪心][高精]P1080 国王游戏(整合)
题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成一排,国王站在队伍的最 ...
- GZOJ 1361. 国王游戏【NOIP2012提高组DAY1】
国王游戏[NOIP2012提高组DAY1] Time Limit:1000MS Memory Limit:128000K Description 国王游戏(game.cpp/c/pas) [问题描述] ...
- 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)
P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成 ...
- NOIP 2012 T2 国王游戏 (贪心+高精)
思路: 呃呃网上那么多题解写得都不错-.. 就是高精 巨坑... 这里展出的是任氏高精(纯自己yy滴) //By SiriusRen #include <cstdio> #include ...
- noip 2012 国王游戏(贪心+高精)
/* 我是不会说我考试的时候想到了正解却把金币取大看成金币求和的.... 觉得只按左右手乘积排序不太对 有反例 也可能我反例放到这个题里是错的吧 按自己的理解排的序 就是各种讨论... 假设 第i个人 ...
- 洛谷 P1080 国王游戏 题解
原题 传送门 思路 分析 我们先假设队伍如下: People left hand right hand Before \(S_a\) A \(a_1\) \(b_1\) B \(a_2\) \(b_2 ...
- [bzoj2729][HNOI2012]排队 题解 (排列组合 高精)
Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...
- [NOIp2012] 国王游戏(排序 + 贪心 + 高精度)
题意 给你两个长为 \(n+1\) 的数组 \(a,b\) ,你需要定义一个顺序 \(p\) (\(p_0\) 永远为 \(0\)) 能够最小化 \[ \max_{i=1}^{n} \frac{\pr ...
- luoguP1080 国王游戏 (贪心+高精度)
题目链接:https://www.luogu.org/problemnew/show/P1080 参考:https://www.luogu.org/problemnew/solution/P1080 ...
随机推荐
- jquery实现表单验证与页面加载之后执行渲染
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- windows下安装oracle11g
第一步:一定要先做这一步. Oracle11g 安装过程出现提示:未找到文件 D:\app\Administrator\product\11.2.0\dbhome_2\owb\external\oc4 ...
- Windows程序设计--(四)文本输出
4.1 绘制和重绘 4.1.2 有效矩阵和无效矩阵 在擦除对话框之后,需要重画的被对话框遮住的矩形区域,这个区域称为「无效区域」或「更新区域」.正是显示区域内无效区域的存在,才会让Windows将一个 ...
- socket - Linux 套接字
总览 #include <sys/socket.h> mysocket = socket(int socket_family, int socket_type, int protocol) ...
- smbumount - 为普通用户卸载smb文件系统
总览 smbumount 装载点 描述 普通用户使用这个程序可以卸载smb文件系统.它在工作时会suid到root身份,并且向普通linux用户提供了对资源更多的控制能力.在suid方面,它拥有足够的 ...
- Git --06 Git-gui安装
目录 1.Git-gui安装 1.Git-gui安装
- qt opencv 视频分析
脱岗 越线 qimage qpixmap opencv 回调视频采集
- 前端学习(三十八)vue(笔记)
Angular+Vue+React Vue性能最好,Vue最轻=======================================================Angular ...
- 【Leetcode周赛】从contest-81开始。(一般是10个contest写一篇文章)
Contest 81 (2018年11月8日,周四,凌晨) 链接:https://leetcode.com/contest/weekly-contest-81 比赛情况记录:结果:3/4, ranki ...
- java static在成员方法中
package java08; public class Myclass { int num;//成员变量 static int numStatic;//静态变量 //成员方法 public void ...