[Luogu] 国王游戏
https://www.luogu.org/problemnew/show/P1080
按照 a * b 排序
高精度
#include <bits/stdc++.h> using namespace std;
const int N = ; #define LL long long int n, ak, bk;
struct Node {
int A, B, AB;
bool operator <(const Node a) const{return AB < a.AB;}
} G[N]; #define gc getchar() LL sum, Answer = ; inline int read() {
int x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c < '') x = x * + c - '', c = gc;
return x;
} int main() {
n = read(); ak = read(); bk = read();
for(int i = ; i <= n; i ++) G[i].A = read(), G[i].B = read(), G[i].AB = G[i].A * G[i].B;
sort(G + , G + n + );
sum = ak;
for(int i = ; i <= n; i ++) {
LL imp = sum / G[i].B;
if(!imp) imp = ;
Answer = max(Answer, imp);
sum *= G[i].A;
}
if(Answer == ) Answer = ;
cout << Answer;
return ;
}
/*
3
1 1
2 3
7 4
4 6
*/
#include <bits/stdc++.h>
using namespace std;
int now[],sum[],ans[],add[];
struct Node {
int a;
int b;
long long a_b;
} node[];
int read() {
int ans = , flag = ;
char ch = getchar();
while( (ch > '' || ch < '') && ch != '-' ) ch = getchar();
if(ch == '-') flag = -, ch = getchar();
while(ch >= '' && ch <= '') ans = ans * + ch - '', ch = getchar();
return ans * flag;
}
void times(int x) {
memset(add, , sizeof(add));
for(int i = ; i <= ans[]; i ++) {
ans[i] = ans[i] * x;
add[i+] += ans[i] / ;
ans[i] %= ;
}
for(int i = ; i <= ans[] + ; i ++) {
ans[i] += add[i];
if(ans[i]>=) {
ans[i+]+=ans[i]/;
ans[i]%=;
}
if(ans[i]!=) {
ans[]=max(ans[],i);
}
}
return ;
}
int divition(int x) {
memset(add,,sizeof(add));
int q=;
for(int i=ans[]; i>=; i--) {
q*=;
q+=ans[i];
add[i]=q/x;
if(add[]== && add[i]!=) {
add[]=i;
}
q%=x;
}
return ;
}
bool compare() {
if(sum[]==add[]) {
for(int i=add[]; i>=; i--) {
if(add[i]>sum[i]) return ;
if(add[i]<sum[i]) return ;
}
}
if(add[]>sum[]) return ;
if(add[]<sum[]) return ;
}
void cp () {
memset(sum,,sizeof(sum));
for(int i=add[]; i>=; i--) {
sum[i]=add[i];
}
return ;
}
bool cmp(Node a,Node b) {
return a.a_b<b.a_b;
}
int main() {
int n=read();
for(int i=; i<=n; i++) {
node[i].a=read(),node[i].b=read();
node[i].a_b=node[i].a*node[i].b;
}
sort(node+,node+n+,cmp);
ans[]=,ans[]=;
for(int i=; i<=n; i++) {
times(node[i-].a);
divition(node[i].b);
if(compare()) {
cp();
}
}
for(int i=sum[]; i>=; i--)
printf("%d",sum[i]);
return ;
}
[Luogu] 国王游戏的更多相关文章
- Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)
Luogu 1080 [NOIP2012]国王游戏 (贪心,高精度) Description 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己 ...
- Luogu P1080国王游戏(贪心)
国王游戏 题目链接:国王游戏 ps:题目数据说明了要写高精度. 这个题的答案是\(a.l * a.r < b.l * b.r\)按照这个进行排序 题解中大部分只是如何证明排序是: \(a.l * ...
- [noip2012]国王游戏<贪心+高精度>
题目链接: https://vijos.org/p/1779 https://www.luogu.org/problem/show?pid=1080 http://codevs.cn/problem/ ...
- NOIP2012 国王游戏
2国王游戏 (game.cpp/c/pas) [问题描述] 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数 ...
- 【NOIP 2012 国王游戏】 贪心+高精度
题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排 成一排,国王站在队伍 ...
- Codevs 1198 国王游戏 2012年NOIP全国联赛提高组
1198 国王游戏 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 恰逢 H 国国庆,国王邀 ...
- NOIP国王游戏
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- AC日记——国王游戏 洛谷 P1080
国王游戏 思路: 贪心+高精: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 struct Dat ...
- 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)
P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成 ...
随机推荐
- CentOS7 PHP cURL errno 35, 原因:CentOS7中没有安装curl和OpenSSL的最新版
安装OpenSSL的最新版 话不多说,直接上安装步骤 #cd /usr/local/src # 跳过证书获取失败 # wget https://www.openssl.org/source/opens ...
- Django ORM相关的一些操作
一般操作 看专业的官网文档,做专业的程序员! 必知必会13条 <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 ...
- 牛客 133D 挑选队友 (分治FFT)
大意: $n$个人, 分别属于$m$个组, 要求选出$k$个人, 使得每组至少有一人, 求方案数. 显然答案为$\prod((1+x)^{a_i}-1)$的第$k$项系数, 分治$FFT$即可. #i ...
- MySQL 官方样板数据库sakila
Sakila示例数据库最初由MySQL AB文档团队的前成员Mike Hillyer开发,旨在提供可用于书籍,教程,文章,样本等示例的标准模式. Sakila示例数据库还用于突出MySQL的最新功能, ...
- python 使用三种常用的工具包处理图片
matplotlib,PIL(Pillow),Opencv三种常用的作图方式. 使用matplotlib画图,很棒,matplotlib 是python最著名的2D绘图库,它提供了一整套和matlab ...
- Oracle 以及 PLSQL安装
今天重装系统遇到oracle 安装的问题咯 ,oracle安装过程中很多疑难杂症咯 1如果之前装过,记得去删除注册表的Oracle 相关的文件 ,请百度有很多教程咯 2这个必须要勾选的!因为的是11g ...
- SvcUtil.exe工具生成客户端代理类
1.以管理员身份运行vs下命令工具: 2.运行代码示例:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>svcutil http: ...
- windows连接远程服务器报错'SSH' 不是内部或外部命令,也不是可运行的程序 或批处理文件 解决方案
网上在windows下连接远程服务器的步骤如下: 1.打开cmd命令行窗口 2.输入cd ~/.ssh,进入c盘下的.ssh文件 3.输入“ssh root@远程服务器的ip地址”连接远程服务器, b ...
- queryURLParams
let url = 'http://www.douqu.com/index.html?name1=val1&name2=val2'; //1.提取问号后的字符 let asktext = ur ...
- redis----Not only Sql 理论
数据存储的瓶颈:(mysql ==>500万数据就已经很慢了) 1 数据量的总大小,一个机器放不下时 2 数据 的索引,一个机器的内存放不下时 3 访问量(读写混合),一个实例不能承受 Redi ...