每个加油的站可以确定一个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. 蓝桥杯 正则问题(dfs)

    1607: 正则问题 时间限制: 1 Sec  内存限制: 256 MB提交: 34  解决: 13[提交][状态][讨论版] 题目描述 考虑一种简单的正则表达式:只由 x ( ) | 组成的正则表达 ...

  2. Redis在windows实现将数据缓存起来定时更新读取

    实现接口的读取存放在内存中,实现了Web网站直接读取内存数据,大大的减少了访问接口带来的等待时间,这个功能是比较实用的 需要下载一下‘类库’及‘Redis-x64-3.2.100程序包’ 百度云材料下 ...

  3. sql中的高级编程(函数,存储过程,视图)

    一.函数:用sql写一个函数,调用这个函数,返回一张数据表table CREATE FUNCTION FunName ( ) RETURNS @TempTable table ( roleid int ...

  4. 《深入理解Java虚拟机》笔记02 -- 垃圾收集算法

    1. 标记 - 清除算法 先标记出所有需要回收的对象,在标记完成后统一回收所有被标记的对象.它是最基础的收集算法.其他收集算法都是根据其思路,改进其不足之处. 缺点:1) 标记和清除两个阶段的效率都不 ...

  5. codeforces590E Birthday【AC自动机+Floyd+匈牙利算法】

    因为没有重复串,所以把有包含关系的串连边之后是个DAG,也就是二分图,就变成求二分图的最大独立集=n-最小点覆盖=n-最大匹配 关于包含关系,建出AC自动机,然后把串放上去找子串,但是如果每次都一路找 ...

  6. solidity 学习笔记(3) 函数修饰符/继承

    修饰符: 函数修饰符有 constant  view pure 其中 constant和view的功能是一样的  不会消耗gas 也就是说不会做任何存储   constant在5.0以后的版本中被废弃 ...

  7. uoj#348/洛谷P4221 [WC2018]州区划分(FWT)

    传送门(uoj) 传送门(洛谷) 全世界都会子集卷积就咱不会--全世界都在写\(FMT\)就咱只会\(FWT\)-- 前置芝士 或运算\(FWT\)或者\(FMT\) 左转洛谷模板区,包教包会 子集卷 ...

  8. jzoj6003. 【THUWC2019模拟2019.1.16】Square (乱搞)

    题面 题解 不难发现,如果一行最后被染色,那么这行的颜色肯定一样,如果倒数第二个被染色,那么除了被最后一个染色的覆盖的那一部分剩下的颜色肯定一样 于是题目可以转化为每一次删去一行或一列颜色相同的,问最 ...

  9. IT兄弟连 JavaWeb教程 过滤器2

    3  多个过滤器的执行顺序 如果一个Web应用中使用一个过滤器不能解决实际中的业务需要,那么可以部署多个过滤器对业务请求进行多次处理,这样做就组成了一个过滤器链.Web服务器在处理过滤器链时,将按过滤 ...

  10. MySQL (case when then else end)和常用函数用法

    case when then else end 相当于Java的if-else if-else,可以用来在select语句中将要显示的内容替换成另一个内容 更多用法:https://www.cnblo ...