CodeForces 48C D - The Race (Fraction,数学)
每个加油的站可以确定一个alpha的上下界,比如,第i次加油站a[i],前面加了i次油,a[i]*10≤ alpha*i <(a[i]+1)*10。
取最大的下界,取最小的上界,看看两者之间的满足条件的下一个加油站是否唯一。
因为可以用分数,所有就没用double了
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } struct Fra {ll p,q;Fra(ll x = 0,ll y = 1):p(x),q(y){ normal(p,q); }void normal(ll &p,ll &q) { ll g = gcd(p,q); p/=g; q/=g; }Fra operator = (int x) { p = x; q = 1; return *this; }Fra operator = (ll x) { p = x; q = 1; return *this; }Fra operator - () { return {-p,q}; }Fra operator + (Fra &r) {ll m,n;m = p*r.q+r.p*q;n = q*r.q;normal(m,n);return {m,n};}Fra operator += (Fra& r) { return *this = *this+r; }Fra operator - (Fra &r) { return (-r) + *this; }Fra operator -= (Fra &r) { return *this = *this-r; }Fra operator * (Fra &r) {ll m,n;m = p*r.p;n = q*r.q;normal(m,n);return {m,n};}Fra operator *= (Fra &r) { return (*this) = (*this)*r; }Fra operator /(Fra &r) { return Fra(r.q,r.p) * (*this); }Fra operator /=(Fra &r) { return (*this) = (*this)/r; }bool operator == (const Fra& r) const { return p*r.q == r.p*q; }bool operator < (const Fra& r) const { return p*r.q < r.p*q; }void print() { normal(p,q); if(q<0)q = -q,p = -p; printf("%lld/%lld\n",p,q); } };const int maxn = 1e3+5;const ll INF = 1e16; int main() {//freopen("in.txt","r",stdin);int n; scanf("%d",&n);Fra Low(0),High(INF);for(int i = 1; i <= n; i++){int t; scanf("%d",&t);Low = max(Fra(t*10,i),Low);High = min(Fra(t*10+10,i),High);}Low = Fra(n+1)*Low;High = Fra(n+1)*High;int u = (High.p-1)/High.q;int d = (Low.p)/Low.q;if(u/10 != d/10) {puts("not unique");}else {printf("unique\n%d",d/10);}return 0; }
转载于:https://www.cnblogs.com/jerryRey/p/4783571.html
CodeForces 48C D - The Race (Fraction,数学)相关推荐
- Codeforces 671E Organizing a Race (贪心、线段树)
题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...
- Codeforces 658D Bear and Polynomials【数学】
题目链接: http://codeforces.com/contest/658/problem/D 题意: 给定合法多项式,改变一项的系数,使得P(2)=0,问有多少种方法? 分析: 暴力求和然后依次 ...
- Codeforces 963A Alternating Sum 【数论+数学】
官方题解这个样子我觉得说得比较清楚.Z我们可以朴素的预处理出来(注意乘法膜),q的话考点在于[分数取膜]即 (a/b)%P = a* inverse of b %P 这就涉及到算b的逆元,我用的是欧几 ...
- 【CodeForces - 124C】Prime Permutation(数学,思维,小结论)
题干: You are given a string s, consisting of small Latin letters. Let's denote the length of the stri ...
- 【CodeForces - 1047C】Enlarge GCD(数学,枚举,预处理打表,思维)
题干: F先生有n个正整数,a1,a2,...,an 他认为这些整数的最大公约数太小了,所以他想通过删除一些整数来扩大它 您的任务是计算需要删除的最小整数数,以便剩余整数的最大公约数大于所有整数的公约 ...
- 【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)
题干: Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degene ...
- 【CodeForces - 215B 】Olympic Medal (数学,公式推导)
题干: The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is ...
- 【CodeForces - 1047B 】Cover Points (数学,构造,思维)
题干: There are nn points on the plane, (x1,y1),(x2,y2),-,(xn,yn)(x1,y1),(x2,y2),-,(xn,yn). You need t ...
- CodeForces 592C The Big Race
公倍数之间的情况都是一样的,有循环节. 注意min(a,b)>t的情况和最后一段的处理.C++写可能爆longlong,直接Java搞吧...... import java.io.Buffere ...
最新文章
- LeetCode题库第1题 两数之和
- 第二节: 比较EF的Lambda查询和Linq查询写法的区别
- oracle数据块调用存储过程,VC调用存储过程的通用方法(ORACLE篇)
- day4 java中print,printf,println的区别
- 第五章——Pytorch中常用的工具
- C# list删除 另外list里面的元素_python学习笔记第三课:List(列表)
- OpenCore引导配置说明第六版
- 【毕业设计项目】基于单片机的万能红外遥控器 - 嵌入式 物联网 stm32
- DFS+记忆化搜索 -- 简单练习
- BGP手动路由聚合(学习笔记+实验验证)
- 营收、净利双收,贝壳找房稳了?
- 计算机视觉会议论文写作建议顺序及注意事项
- RL(Chapter 3): Finite Markov Decision Processes (有限马尔可夫决策过程)
- 肠道菌群检测粪便样本的采集保存方法
- 大笨钟 (10 分)
- 计算机找不到指纹登陆,Win10电脑上登陆选项没有PIN码和指纹设置的解决教程
- 景安服务器怎么上传网站程序,Web服务器是如何被应用服务器“收编”的?
- Spring?Spring?Spring到底是啥?
- 汽车网络和控制单元的安全威胁研究
- 12V/24V升1500V/2000V/2500V/3000V稳压高压隔离电源模块