Codeforces Round #414 Div.2

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 激动

 

------upd------2017.5.15---------------

B 迷之二分 相似三角形推一推就可以推出来的东西。。。

    

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<iostream>
 4 using namespace std;
 5 typedef long double ld;
 6 int main() {
 7     int n, h;
 8     scanf("%d %d", &n, &h);
 9     for (int i = 1; i < n; ++i) {
10         printf("%.12Lf ", sqrt((ld)(i) / (ld)(n)) * (ld)(h));
11     }
12     return 0;
13 }
View Code

 输出 long double 类型用 %Lf

posted @ 2017-05-13 20:58  p0ny  阅读(264)  评论(2编辑  收藏  举报