Task: | Build a Boat |
Sender: | Game of Nolife |
Submission time: | 2016-11-12 14:29:04 +0200 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.08 s | details |
#3 | ACCEPTED | 0.05 s | details |
#4 | ACCEPTED | 0.08 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | ACCEPTED | 0.06 s | details |
#7 | ACCEPTED | 0.06 s | details |
#8 | ACCEPTED | 0.06 s | details |
#9 | ACCEPTED | 0.06 s | details |
#10 | ACCEPTED | 0.05 s | details |
#11 | ACCEPTED | 0.08 s | details |
Code
#include <bits/stdc++.h> #define F first #define S second #define X real() #define Y imag() using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> co; co pts[101010]; const ld eps=1e-9; ld getAr(co a, co b, ld x1, ld x2) { if (x2-x1<eps) return 0; ld par1=(x1-a.X)/(b.X-a.X); ld par2=(x2-a.X)/(b.X-a.X); co aa=a+par1*(b-a); co bb=a+par2*(b-a); return (bb.Y+aa.Y)*(bb.X-aa.X)/2; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ld c; cin>>c; int n; cin>>n; int leind=-1; ld parsa=1e7; for (int i=0;i<n;i++) { ld x,y; cin>>x>>y; if (x<parsa) { parsa=x; leind=i; } pts[i]={x,y}; } pts[n]=pts[0]; ld ar=0; for (int i=0;i<n;i++) { ar+=(pts[i].Y+pts[i+1].Y)*(pts[i].X-pts[i+1].X)/2; } ar=abs(ar); ld mm=floor(ar/c); ll m=mm; cout<<m<<"\n"; int ptr1=leind; int ptr2=leind; ld acAr=0; ld xx=pts[leind].X; cout<<setprecision(15); for (ll i=1;i<m;i++) { while (acAr<(i*ar)/m) { while (ptr1>0 && pts[ptr1-1].X-xx<eps) ptr1--; if (ptr1==0) ptr1=n; while (ptr1>0 && pts[ptr1-1].X-xx<eps) ptr1--; while (ptr2<n && pts[ptr2+1].X-xx<eps) ptr2++; if (ptr2==n) ptr2=0; while (ptr2<n && pts[ptr2+1].X-xx<eps) ptr2++; ld x2=min(pts[ptr1-1].X,pts[ptr2+1].X); // cerr<<x2<<endl; if (acAr+getAr(pts[ptr1-1],pts[ptr1],xx,x2)-getAr(pts[ptr2+1],pts[ptr2],xx,x2)<(i*ar)/m) { acAr+=getAr(pts[ptr1-1],pts[ptr1],xx,x2)-getAr(pts[ptr2+1],pts[ptr2],xx,x2); xx=x2; } else { // cerr<<"taa"<<endl; ld lo=xx; ld hi=x2; for (int ii=0;ii<100;ii++) { ld mid=(lo+hi)/2; if (acAr+getAr(pts[ptr1-1],pts[ptr1],xx,mid)-getAr(pts[ptr2+1],pts[ptr2],xx,mid)<(i*ar)/m) { lo=mid; } else hi=mid; } acAr=(i*ar)/m; xx=lo; } } cout<<xx<<"\n"; } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3330 25 41 319 28 276 72 200 ... |
correct output |
---|
15 69.93518657478368 116.7366844213038 141.6357731528959 171.609786826269 ... |
user output |
---|
15 69.9351865747837 116.736684421304 141.635773152896 171.609786826269 ... |
Test 2
Verdict: ACCEPTED
input |
---|
919746 100000 996 6428 995 6428 995 6428 ... |
correct output |
---|
78 -1530.528630972202 -1309.390935245671 -1122.206263056054 -953.7695175615483 ... |
user output |
---|
78 -1530.5286309722 -1309.39093524567 -1122.20626305605 -953.769517561548 ... |
Test 3
Verdict: ACCEPTED
input |
---|
917799 1000 912 -630 911 -631 910 -632 ... |
correct output |
---|
27 -3465.185579920218 -3163.712040783569 -2895.313958352536 -2641.390181941859 ... |
user output |
---|
27 -3465.18557992022 -3163.71204078357 -2895.31395835254 -2641.39018194186 ... |
Test 4
Verdict: ACCEPTED
input |
---|
277175 100000 2170 -3895 2170 -3895 2170 -3895 ... |
correct output |
---|
90 -3005.257881357356 -2879.633071625344 -2771.662656826568 -2673.251989964648 ... |
user output |
---|
90 -3005.25788135736 -2879.63307162534 -2771.66265682657 -2673.25198996465 ... |
Test 5
Verdict: ACCEPTED
input |
---|
883 57 9 232 20 9 31 235 ... |
correct output |
---|
82 14.1980667997135 17.8823468982338 20.66041839625604 23.53643431160832 ... |
user output |
---|
82 14.1980667997135 17.8823468982338 20.660418396256 23.5364343116083 ... |
Test 6
Verdict: ACCEPTED
input |
---|
4200 40 26 239 498 35 495 69 ... |
correct output |
---|
15 67.35315558599663 89.89076596039594 118.6607533697672 179.4227191272342 ... |
user output |
---|
15 67.3531555859966 89.8907659603959 118.660753369767 179.422719127234 ... |
Test 7
Verdict: ACCEPTED
input |
---|
13561 35 27 219 37 213 49 187 ... |
correct output |
---|
3 170.9402238323747 262.4515849078862 |
user output |
---|
3 170.940223832375 262.451584907886 |
Test 8
Verdict: ACCEPTED
input |
---|
3141592 500 10000 0 9999 62 9996 125 ... |
correct output |
---|
49 -8938.348582329191 -8303.932703876396 -7764.90786515461 -7278.186505377522 ... |
user output |
---|
49 -8938.34858232919 -8303.9327038764 -7764.90786515461 -7278.18650537752 ... |
Test 9
Verdict: ACCEPTED
input |
---|
3141530 10000 10000 0 9999 6 9999 12 ... |
correct output |
---|
99 -9338.328301675262 -8945.754530183002 -8613.952801637244 -8315.767480032278 ... |
user output |
---|
99 -9338.32830167526 -8945.754530183 -8613.95280163724 -8315.76748003228 ... |
Test 10
Verdict: ACCEPTED
input |
---|
17411 50 1000 0 992 62 968 124 ... |
correct output |
---|
89 -927.3615790510609 -885.1172474645925 -849.4735324335133 -817.3603922657395 ... |
user output |
---|
89 -927.361579051061 -885.117247464593 -849.473532433513 -817.360392265739 ... |
Test 11
Verdict: ACCEPTED
input |
---|
949050 100000 -2277 -1215 -2277 -1215 -2278 -1215 ... |
correct output |
---|
75 -2087.626257450405 -1860.533764609684 -1668.250903711116 -1495.160391614835 ... |
user output |
---|
75 -2087.6262574504 -1860.53376460968 -1668.25090371112 -1495.16039161484 ... |