标签:http os io for ar ios a blank
题目链接:点击打开链接
题意:
给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油。
在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油。
开始有x升油
下面给出加油的记录。
问下一次加油在哪一站。若答案唯一输出具体哪站。
油箱容量无限
思路:
水模拟。。
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <iostream> using namespace std; #define gg 10.0 #define N 1005 #define eps (1e-6) #define ll int double p[N]; ll n; void input(){ for(ll i = 1; i <= n; i++)cin>>p[i]; } double ok(double x){ double now = x; double siz = 0; for(ll i = 1; i <= n; i++) { siz += floor(now/gg); now -= floor(now/gg)*gg; if(siz != p[i]){ double cha = (p[i] - siz)*10.0 - now; now = 0; x += cha / i; } siz = p[i]; now += x; } return now; } double ok2(double x){ double now = x; double siz = 0; for(ll i = 1; i <= n; i++) { siz += floor(now/gg); now -= floor(now/gg)*gg; if(siz != p[i]){ double cha = (siz - p[i])*10.0 - (10.0-now-eps); now = 10.0 - eps; x -= cha / i; } siz = p[i]; now += x; } return now; } int main(){ ll i, j; while(cin>>n){ input(); double l = ok(p[1]*10.0) + eps; double r = ok2(p[1]*10.0 + 10.0); l = floor(l/10.0); r = floor(r/10.0); if(l == r) { puts("unique"); printf("%.0lf\n", p[n] + l); } else puts("not unique"); } return 0; }
Codeforces 48C The Race 模拟题,布布扣,bubuko.com
标签:http os io for ar ios a blank
原文地址:http://blog.csdn.net/qq574857122/article/details/38173339