每个加油的站可以确定一个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 = ,ll y = ):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 = ; return *this; }
Fra operator = (ll x) { p = x; q = ; 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<)q = -q,p = -p; printf("%lld/%lld\n",p,q); }
}; const int maxn = 1e3+; const ll INF = 1e16;
int main()
{
//freopen("in.txt","r",stdin);
int n; scanf("%d",&n);
Fra Low(),High(INF);
for(int i = ; i <= n; i++){
int t; scanf("%d",&t);
Low = max(Fra(t*,i),Low);
High = min(Fra(t*+,i),High);
}
Low = Fra(n+)*Low;
High = Fra(n+)*High;
int u = (High.p-)/High.q;
int d = (Low.p)/Low.q;
if(u/ != d/) {
puts("not unique");
}else {
printf("unique\n%d",d/);
}
return ;
}

CodeForces 48C D - The Race (Fraction,数学)的更多相关文章

  1. Continued Fractions CodeForces - 305B (java+高精 / 数学)

    A continued fraction of height n is a fraction of form . You are given two rational numbers, one is ...

  2. Codeforces Round #328 (Div. 2) C 数学

    C. The Big Race time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. Codeforces 735C:Tennis Championship(数学+贪心)

    http://codeforces.com/problemset/problem/735/C 题意:有n个人打锦标赛,淘汰赛制度,即一个人和另一个人打,输的一方出局.问这n个人里面冠军最多能赢多少场, ...

  4. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

  5. Codeforces Gym 100002 D"Decoding Task" 数学

    Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  6. Codeforces Round #372 (Div. 2) C 数学

    http://codeforces.com/contest/716/problem/C 题目大意:感觉这道题还是好懂得吧. 思路:不断的通过列式子的出来了.首先我们定义level=i, uplevel ...

  7. Codeforces 839D Winter is here【数学:容斥原理】

    D. Winter is here time limit per test:3 seconds memory limit per test:256 megabytes input:standard i ...

  8. CodeForces - 375A Divisible by Seven(数学)

    https://vjudge.net/problem/48715/origin 题意:给出必定含1689四个数字的字符串,随意交换位置构造出能被7整除的数. 分析:数学思维题.观察发现1689的排列与 ...

  9. Codeforces 582C. Superior Periodic Subarrays(数学+计数)

    首先可以把 i mod n=j mod n的看成是同一类,i mod s=j mod s的也看成是同一类,也就是i mod gcd(s,n)的是同一类,很好理解,但是不会数学证明...大概可以想成数轴 ...

随机推荐

  1. 将Opencv java中的Mat通过jni传递到C++中的方法

    public native void FindFeatures(long matAddrGr, long matAddrRgba); ... mRgba = new Mat(height, width ...

  2. <!--[if !IE]> 的用法

    除IE外都可识别

  3. PHP json 对象 数组互相转换

    json格式转为数组/对象 json_decode() json 对象/数组转json格式 json_encode()

  4. 计算机视觉(CV)前沿国际国内期刊与会议

    计算机视觉(CV)前沿国际国内期刊与会议1.国际会议 2.国际期刊 3.国内期刊 4.神经网络 5.CV 6.数字图象 7.教育资源,大学 8.常见问题 1. 国际会议现在,国际上计算机视觉方面的三大 ...

  5. vijos1007 绕钉子的长绳子

    P1007绕钉子的长绳子(https://vijos.org/p/1007) 背景 平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形. 现在你要用一条绳子把这些钉子围起来,绳子直径忽略 ...

  6. Git 深度学习填坑之旅二(文件三种状态、打标签)

    0x01 三种状态 Git 有三种状态,你的文件可能处于其中之一: 已提交(committed).已修改(modified)和已暂存(staged). 已提交表示数据已经安全的保存在本地数据库中. 已 ...

  7. vue中params & query的比较

    共同点: 1.都可以传值 2.在另外一个组件中传递值的时候,都是放在$route中 不同点: 1.传值时候,url的表现不一样 query /orderInfo?xxx=yyy&aaa=bbb ...

  8. MySQL 的视图、触发器、事务、存储过程、函数

    MySQL 的视图.触发器.事务.存储过程.函数   阅读目录 一 视图 二 触发器 三 事务 四 存储过程 五 函数 六 流程控制 一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句 ...

  9. Djano调试工具debug-toolbar

    Djano调试工具debug-toolbar   django-debug-toolbar 调试工具使用文档 安装 pip install django-debug-toolbar 配置 在setti ...

  10. xxe漏洞分析

    xxe漏洞总结 xxe漏洞就是xml外部实体注入攻击,所以一定是针对xml编写的服务. xxe漏洞是把参数经过php输入流或者$HTTP_RAW_POST_DATA直接读入xml实体当中,参数可控且没 ...