Codeforces 48C The Race 類比題

來源:互聯網
上載者:User

標籤: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 intdouble 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;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.