[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 位大臣排成 ...
随机推荐
- Python 【格式化字符串】
print('血量:'+str(player_life)+' 攻击:'+str(player_attack)) 第一种格式化字符串 print('血量:%s 攻击:%s' % (player_life ...
- k8s-traefik默认80端口
vim traefik.yaml kind: Deployment apiVersion: extensions/v1beta1 metadata: name: traefik-ingress-con ...
- 实例详解jQuery的无new构建
jQuery的无new构建 jQuery框架的核心就是从HTML文档中匹配元素并对其执行操作. 回想一下使用 jQuery 的时候,实例化一个 jQuery 对象的方法: // 无 new 构造 $( ...
- Python字符串的常用方法总结
tring.capitalize() 把字符串的第一个字符大写 string.center(width) 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串 , end=len(str ...
- ubuntu中安装字体雅黑和consolas
Ubuntu的群体里偏向使用雅黑,我目前用的YaHei.Consolas 1.11 版本 (雅黑-Consolas的混合体) http://www.netmako.com/RobertLee/YaHe ...
- 查找最大和次大元素(JAVA版)(分治法)
问题描述:对于给定的含有n个元素的无序序列,求这个序列中最大和次大的两个不同元素. 问题求解分析(分治法):先给出无序序列数组a[low...high].第一种情况为当数组中只有一个元素时,此时只存在 ...
- 关于dataset
举个栗子: <div id="cost" data-drink="coffee" data-food="sushi" data-mea ...
- 简要了解web安全之sql注入
什么是sql注入? 通俗来讲就是通过 将可执行sql语句作为参数 传入查询sql 中,在sql编译过程中 执行了传入进来的恶意 sql,从而 得到 不应该查到或者不应该执行的sql语句,对网站安全,信 ...
- 【Mac】 开启原生的 NTFS 硬盘格式支持
一.MacOS 10.13 之前 二.MacOS 10.13 及之后 一.MacOS 10.13 之前 直接跳到引用地址查看,下面的草记只是为了防止链接丢失 引用地址 打开终端 切换至root身份,输 ...
- windows10 L2tP nat 下无法连接的处理
事件查看器中没有错误代码显示. Windows 10 L2TP/IPsec Manual Setup Instructions Bold items are things you will click ...