每个加油的站可以确定一个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. Linux Ubuntu下Jupyter Notebook的安装

    Jupyter Notebook, 以前又称为IPython notebook,是一个交互式笔记本, 支持运行40+种编程语言. 可以用来编写漂亮的交互式文档. 安装步骤: pip install - ...

  2. SQL Server(二)——语句 转

    表的创建: 1.创建列(字段):列名+类型 2.设置主键列(primary key):能够唯一标识一条数据 3.设置唯一(unique):内容不能重复 4.外键关系:一张表(从表)其中的某列引用自另外 ...

  3. Unity命令行打包

    http://www.66acg.com/?post=137 补充 unity编辑器端获取打包命令行自定义参数,这个可以获取到所有打包时的参数 string[] runArgs = System.En ...

  4. hdu1698(线段树区间替换模板)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意: 第一行输入 t 表 t 组测试数据, 对于每组测试数据, 第一行输入一个 n , 表示 ...

  5. 洛谷P3431 [POI2005]AUT-The Bus

    P3431 [POI2005]AUT-The Bus 题目描述 The streets of Byte City form a regular, chessboardlike network - th ...

  6. .NET 基础 一步步 一幕幕[XML基础操作]

    XML可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言. 什么是XML,学他有什么用? 优点:容易读懂,格式标准任何语言都内置了XML分析引擎,不用单独进行文件分 ...

  7. 开发中mybatis的一些常见问题记录

    一.oracle数据库通过mybatis的批量插入的两种方式 方式1 insert into table_tmp (id,v1,v2,v3,v4) SELECT A.*,OSM_VIID_DEVICE ...

  8. 项目模板eShopOnContainers

    .NET Core多平台项目模板eShopOnContainers编译手记   之前写了一个功能性的文件上传asp.net core的小程序,加上点七七八八的东西,勉强能够应付了,打算学习一下微软的官 ...

  9. 线程池ThreadPoolExecutor的学习

    我们知道,ExecutorService是一个抽象出线程池的一个接口,然后我们在使用线程池的时候,用的是Executors工具类中的一系列newCachedThreadPool() 等类似的方法,这些 ...

  10. C# 实现本地化日志管理

    1.新建一个类库解决方案 CommnoLog 2.新建两个文件夹 2.1FileUtil.cs  代码如下 public static class FileUtil { /// <summary ...