1. 程式人生 > >Codeforces Round #414 Div.2

Codeforces Round #414 Div.2

span main pre style namespace one ret == hide

A 膜你

技術分享
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 int main() {
 6     int a, b, c, n, ans = 0;
 7     scanf("%d %d %d", &a, &b, &c);
 8     scanf("%d", &n);
 9     for (int p, i = 0; i < n; ++i) {
10         scanf("%d", &p);
11         if
(b < p and p < c) ++ans; 12 } 13 printf("%d\n", ans); 14 return 0; 15 }
View Code

B 二分高

技術分享
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 using namespace std;
 5 double eps = 1e-10;
 6 double ans = 0, up = 0, each, down;
 7 int n, h0;
 8 inline int check(double
h) { 9 down = (ans + h) / h0; 10 double area = (up + down) * h * 0.5; 11 if (abs(area - each) <= eps) 12 return 0; 13 else if (area > each) return -1; 14 else return 1; 15 } 16 17 18 int main() { 19 scanf("%d %d", &n, &h0); 20 each = h0 * 0.5 / n; 21 for
(int i = 1; i < n; ++i) { 22 double l = 0, r = h0, h = 0; 23 for (int j = 0; j < 300; ++j) { 24 double mid = (l + r) / 2; 25 int res = check(mid); 26 if (!res) {h = mid; break;} 27 if (res == 1) { 28 h = l = mid; 29 } else { 30 h = r = mid; 31 } 32 } 33 ans += h; up = down; 34 printf("%.12lf ", ans); 35 } 36 puts(""); 37 return 0; 38 }
View Code

CDE 蒟蒻不會

人生第二次漲rating 激動

Codeforces Round #414 Div.2