Tozan and Gezan(x*y<a*b)
E - Tozan and Gezan
Time limit : 2sec / Memory limit : 256MB
Score : 700 points
Problem Statement
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is Ai, and the i-th element in B is Bi.
Tozan and Gezan repeats the following sequence of operations:
- If A and B are equal sequences, terminate the process.
- Otherwise, first Tozan chooses a positive element in A and decrease it by 1.
- Then, Gezan chooses a positive element in B and decrease it by 1.
- Then, give one candy to Takahashi, their pet.
Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.
Constraints
- 1≤N≤2×105
- 0≤Ai,Bi≤109(1≤i≤N)
- The sums of the elements in A and B are equal.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A1 B1
:
AN BN
Output
Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.
Sample Input 1
2
1 2
3 2
Sample Output 1
2
When both Tozan and Gezan perform the operations optimally, the process will proceed as follows:
- Tozan decreases A1 by 1.
- Gezan decreases B1 by 1.
- One candy is given to Takahashi.
- Tozan decreases A2 by 1.
- Gezan decreases B1 by 1.
- One candy is given to Takahashi.
- As A and B are equal, the process is terminated.
Sample Input 2
3
8 3
0 1
4 8
Sample Output 2
9
Sample Input 3
1
1 1
Sample Output 3
0 题意:求满足条件x*y<a*b最多的组数,其中a,b已知。
题解:要满足<a*b,x,y中必定存在<sqrt(a*b)的数;
① 如果t2*t2==a*b,在满足a==b的条件下,因为是<a*b,所以t2*2—2,因为a,b被计算了两次;否则在t2*t2==a*b的各种情况中还存在a!=t2&&a!=b的情况,所以还要-1;
② 如果满足t2*t2为最后一组满足条件的数时,只需要-1,(重复计算了t2*t2);
③ 否则的话-2(即在分别为a和b的条件时的两种情况; AC代码:
//#include <bits/stdc++.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define N 500005
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
#define MOD 998244353
#define Mod 1e9 + 7
template<typename T> inline T max(T a,T b,T c){
return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
return min(a,min(b,c,d));
}
const int dx[]={,,,-,,,-,,-};
const int dy[]={,,,,-,,-,-,};
typedef long long ll;
using namespace std;
int main(){
ll n,a,b;
scanf("%lld",&n);
for (int i=;i<=n;i++){
scanf("%lld%lld",&a,&b);
ll t1=a*b;
ll t2=sqrt(t1);
if (t2*t2==t1){
if (a==b) printf("%lld\n",t2*-);
else printf("%lld\n",t2*-);
}
else if (t2*(t2+)<t1) printf("%lld\n",t2*-);
else printf("%lld\n",t2*-);
}
return ;
}
Tozan and Gezan(x*y<a*b)的更多相关文章
- 给定n,求1/x + 1/y = 1/n (x<=y)的解数~hdu-1299~(分解素因子详解)
链接:https://www.nowcoder.com/acm/contest/90/F来源:牛客网 题目描述 给定n,求1/x + 1/y = 1/n (x<=y)的解数.(x.y.n均为正整 ...
- 青蛙的约会 扩展欧几里得 方程ax+by=c的整数解 一个跑道长为周长为L米,两只青蛙初始位置为x,y;(x!=y,同时逆时针运动,每一次运动分别为m,n米;问第几次运动后相遇,即在同一位置。
/** 题目:青蛙的约会 链接:https://vjudge.net/contest/154246#problem/R 题意:一个跑道长为周长为L米,两只青蛙初始位置为x,y:(x!=y,同时逆时针运 ...
- 省赛i题/求1~n内所有数对(x,y),满足最大公约数是质数的对数
求1~n内所有数对(x,y),gcd(x,y)=质数,的对数. 思路:用f[n]求出,含n的对数,最后用sum[n]求和. 对于gcd(x,y)=a(设x<=y,a是质数),则必有gcd(x/a ...
- 省赛i题/求1~n内全部数对(x,y),满足最大公约数是质数的对数
求1~n内全部数对(x,y),gcd(x,y)=质数,的对数. 思路:用f[n]求出,含n的对数.最后用sum[n]求和. 对于gcd(x,y)=a(设x<=y,a是质数),则必有gcd(x/a ...
- X分钟速成Y (其中Y=Python3)
# 用井字符开头的是单行注释 """ 多行字符串用三个引号 包裹,也常被用来做多 行注释 """ ##################### ...
- 已知(x,y,z,yaw,pitch,roll)如何得到4*4的转换矩阵?
作者:Nicholas链接:https://www.zhihu.com/question/41514206/answer/104827395来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商 ...
- IOS 封装View的fram(X Y W H )
@interface UIView (Extension) @property (nonatomic, assign) CGFloat x; @property (nonatomic, assign) ...
- 最小二乘求解常数k使得kx=y(x,y为列向量)
直接求解法 取范数 \[ E(k)=\|kx-y\|^{2}\\ \] 构建最小二乘得出 \[ \arg \min (E(k))=k^2x^Tx+y^Ty-2x^Tyk \] 对k求导有 \[ 2x^ ...
- 中心极限定理(为什么y服从高斯分布)
因为每一条数据都服从IID原则: 根据中心极限定理,当数据增加的时候,样本均值的分布慢慢变成正态分布 不管分布式什么分布,累加起来都是高斯分布 As sum increases, sum of non ...
随机推荐
- 由AnnotatedElementUtils延伸的一些所思所想
这篇博客的两个主题: spring的AnnotatedElementUtils 个人源码阅读方法论分享 为什么要分享AnnotatedElementUtils这个类呢,这个类看起来就是一个工具类,听起 ...
- 项目开发git-短信验证-redis数据库
项目开发git操作 基本流程 """ 1.开发前,拉一次远程仓库 2.工作区进行开发 3.将开发结果提交到本地版本库 - git status查看时没有待处理的事件 4. ...
- ZJNU 1538 - YN!ngC的取子游戏--高级
Nim博弈 因为移动到第0阶会消失 所以可以得到从最后一个人操作必定是把第1阶所有子全部移动到第0阶 递推可得,最后一个能把奇数阶的子移动到偶数阶上的人将会必胜 所以这个必胜条件就是奇数阶上的子全部为 ...
- Python笔记_第一篇_面向过程第一部分_6.循环控制语句(while 和 for)_
承接条件控制语句.条件控制语句像大树一样有很多的之差,那条路径通(也就是表达式判断为True)就会往哪一个树杈去运行,万涓溪水汇成大河.对于常用的程序结构形式,还有一种这篇文章就会讲解,那就是循环控制 ...
- 启动查看crontab日志服务
方法1: . 修改rsyslog文件,将/etc/rsyslog.d/-default.conf 文件中的#cron.*前的#删掉: . 重启rsyslog服务service rsyslog rest ...
- iTOP-4418开发板_重实力_优势突出_有原理图源码开源
核心板参数 尺寸:50mm*60mm 高度:核心板连接器组合高度1.5mm PCB层数:6层PCB沉金设计 4418 CPU:ARM Cortex-A9 四核 S5P4418处理器 1.4GHz 68 ...
- 一个简单的jQuery回调函数例子
jQuery回调函数简单使用 比如说,我们想要点击某个按钮后触发事件, 先把一些指定内容给隐藏掉, 然后跳出相关信息的对话框. 如果使用普通的方法, 不用回调函数的话, 会有怎么样的效果呢? 效果是先 ...
- 浅谈PHP小马免杀
在渗透测试过程初期,上传小马,拿到 webshell 再进行下一步的操作,现如今的网站安全更多是 一些云防护.CDN防护.服务器安全软件等等,给渗透测试.提权等带来了一定难度的提升, 今天探讨一下如何 ...
- fcntl()函数之非阻塞模型
优点:设置标准输入为非阻塞(有数据则读 没有数据则立即返回),常用于网络通信以及轻量信息多并发中 步骤: 1.oldflag=fcntl(STDIN_FILENO,F_GETFL); 获取标准输入的文 ...
- Django学习之路由层
Django请求生命周期 - wsgi, 他就是socket服务端,用于接收用户请求并将请求进行初次封装,然后将请求交给web框架(Flask.Django) - 中间件,帮助我们对请求进行校验或在请 ...