luoguP1080 国王游戏 题目

#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)(贪心+高精)的更多相关文章

  1. [贪心][高精]P1080 国王游戏(整合)

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

  2. GZOJ 1361. 国王游戏【NOIP2012提高组DAY1】

    国王游戏[NOIP2012提高组DAY1] Time Limit:1000MS Memory Limit:128000K Description 国王游戏(game.cpp/c/pas) [问题描述] ...

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

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

  4. NOIP 2012 T2 国王游戏 (贪心+高精)

    思路: 呃呃网上那么多题解写得都不错-.. 就是高精 巨坑... 这里展出的是任氏高精(纯自己yy滴) //By SiriusRen #include <cstdio> #include ...

  5. noip 2012 国王游戏(贪心+高精)

    /* 我是不会说我考试的时候想到了正解却把金币取大看成金币求和的.... 觉得只按左右手乘积排序不太对 有反例 也可能我反例放到这个题里是错的吧 按自己的理解排的序 就是各种讨论... 假设 第i个人 ...

  6. 洛谷 P1080 国王游戏 题解

    原题 传送门 思路 分析 我们先假设队伍如下: People left hand right hand Before \(S_a\) A \(a_1\) \(b_1\) B \(a_2\) \(b_2 ...

  7. [bzoj2729][HNOI2012]排队 题解 (排列组合 高精)

    Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...

  8. [NOIp2012] 国王游戏(排序 + 贪心 + 高精度)

    题意 给你两个长为 \(n+1\) 的数组 \(a,b\) ,你需要定义一个顺序 \(p\) (\(p_0\) 永远为 \(0\)) 能够最小化 \[ \max_{i=1}^{n} \frac{\pr ...

  9. luoguP1080 国王游戏 (贪心+高精度)

    题目链接:https://www.luogu.org/problemnew/show/P1080 参考:https://www.luogu.org/problemnew/solution/P1080 ...

随机推荐

  1. MySQL的数据类型:文本、数字、日期/时间

    在MySQL中,有三种主要的类型:文本.数字和日期/时间类型. 文本类型(text):数据类型                                 描述 CHAR(size) 保存固定长度 ...

  2. JavaScript给动态插入的元素添加事件绑定

    由于实际的需要,有时需要往网页中动态的插入HTML内容,并在插入的节点中绑定事件处理函数.我们知道,用Javascript向HTML文档中 插入内容,有两种方法, 一种是在写HTML代码写入JS,然后 ...

  3. Linux学习笔记2-CentOS7安装tomcat8

    1.下载tomcat:apache-tomcat-8.5.16.tar.gz 下载地址:http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat ...

  4. Polish orthography

    Computer encoding[edit] There are several different systems for encoding the Polish alphabet for com ...

  5. java 两个对象共使一个方法

  6. sqlserver 之 将查询结果变为json字符串

    GO /****** Object: StoredProcedure [dbo].[SerializeJSON] Script Date: 6/4/2019 3:58:23 PM 将查询结果变为jso ...

  7. .net core 添加NLog

    依赖项——右键——管理NuGet程序包——浏览——输入以下内容 Install-Package NLog.Extensions.Logging -Pre 在根目录下添加nlog.config   更改 ...

  8. hdu 4235 容斥原理模板题

    题目大意: 输入样例个数T,每个样例输入三个数a,b,n,求[a,b]之间与n互素的个数 基本思路: 互斥,想想这个:AUBUC=A+B+C-A∩B-A∩C-B∩C+A∩B∩C fac存的是n的素因数 ...

  9. 刷题or源码链接

    Hadoop权威指南的Github https://github.com/tomwhite/hadoop-book hadoopAPI http://hadoop.apache.org/docs/cu ...

  10. Testng报错:method-selectors?,parameter*,groups?,packages?,classes?

    以上的报错信息有两种可能的原因: 1.xml的格式确实有误 2.xml的格式正确,但是工程中testng的jar包不止一个,从而导致有歧义或者冲突(这个很可能发生在同一个workspace有多个工程的 ...