2015 Baidu star preliminary round (1) question (1001), 20151001
1001: simple greedy questions. First, we determine the two States (max <m, min> m) that must win and lose, and then sort the combat capability in the order of 0 ~ The maximum combat force between m is the initial value,
Then, each time the attack power is raised to the next big man's value, k -- at the same time, if it is found that it cannot beat, it will lose, break. Pay attention to the combat power of 1e12, with _ int64
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>using namespace std;__int64 s[10005];int main(){__int64 T, n, m, k;scanf("%I64D", &T);__int64 cas = 1;while (T--){scanf("%I64D%I64D%I64D", &n,&m,&k);for (__int64 i = 1; i <= n; i++)scanf("%I64D", &s[i]);sort(s + 1, s + n + 1);cout << "Case #" << cas++ << ":" << endl;if (s[n] <= m)printf("why am I so diao?\n");else if (s[1] > m)printf("madan!\n");else{__int64 ind = 0;for (__int64 i = 1; i <= n; i++){if (s[i] >= 0 && s[i] <= m)ind = i;}__int64 attack = s[ind]; int flag = 1; for (__int64 i = ind; i <= n; i++){if (attack < s[i]){flag = 0;break;}else if (attack == s[i]){if (i + 1 <= n&&attack + k >= s[i + 1]){attack = attack + s[i + 1] - s[i];k--;k = max(k, (__int64)0);}}}if (flag)printf("why am I so diao?\n");elseprintf("madan!\n");}}return 0;}
1006:
Minimum rectangle overwrite, template question. Note that the result is rounded in.
# Include <stdio. h> # include <iostream> # include <string. h> # include <cstring> # include <algorithm> # include <math. h> using namespace std; # define PR 1e-8 # define N 4010 # define maxdouble 1e20int T, n, ans; struct TPoint {double x, y ;}; struct TPolygon {int n; TPoint p [N];} ply; double MIN (double a, double B) {return a> B? B: a;} int dblcmp (double a) {if (fabs (a) <PR) return 0; return a> 0? 1:-1;} double dist (TPoint a, TPoint B) // distance {double s1 =. x-B. x; double t1 =. y-B. y; return sqrt (s1 * s1 + t1 * t1);} double cross (TPoint a, TPoint B, TPoint c) // cross Product {double s1 = B. x-. x; double t1 = B. y-. y; double s2 = c. x-. x; double t2 = c. y-. y; return s1 * t2-s2 * t1;} double dot (TPoint a, TPoint B, TPoint c) // Point product {double s1 = B. x-. x; double t1 = B. y-. y; double s2 = c. x-. x; double t2 = c. y-. y; return s1 * s2 + t1 * t2;} bool cmop (TPoint a, TPoint B) // x, y sort {if (fabs (. x-B. x) <PR) return. y <B. y; else return. x <B. x;} bool cmp (TPoint a, TPoint B) // sorting in the cross Product {int d1 = dblcmp (cross (ply. p [0], a, B); return d1> 0 | (d1 = 0 & dist (ply. p [0], a) <dist (ply. p [0], B);} TPolygon graham () // returns the convex packet {int I, top = 2; for (I = 2; I <ply. n; I ++) {while (top> 1 & (dblcmp (cross (ply. p [top-2], ply. p [I], ply. p [top-1])> = 0) top --; ply. p [top ++] = ply. p [I];} ply. n = top; return ply;} double solve () {int I, p = 1, q = 1, r; double minarea = maxdouble, area; ply. p [ply. n] = ply. p [0]; for (I = 0; I <ply. n; I ++) {while (dblcmp (cross (ply. p [I], ply. p [I + 1], ply. p [p + 1]) // the top point-cross (ply. p [I], ply. p [I + 1], ply. p [p])> 0) p = (p + 1) % ply. n; while (dblcmp (dot (ply. p [I], ply. p [I + 1], ply. p [q + 1]) // the rightmost point-dot (ply. p [I], ply. p [I + 1], ply. p [q])> 0) q = (q + 1) % ply. n; if (I = 0) r = q; while (dblcmp (dot (ply. p [I], ply. p [I + 1], ply. p [r + 1]) // The leftmost point-dot (ply. p [I], ply. p [I + 1], ply. p [r]) <= 0) r = (r + 1) % ply. n; double d = dist (ply. p [I], ply. p [I + 1]) * dist (ply. p [I], ply. p [I + 1]); area = cross (ply. p [I], ply. p [I + 1], ply. p [p]) * (dot (ply. p [I], ply. p [I + 1], ply. p [q])-dot (ply. p [I], ply. p [I + 1], ply. p [r])/d; minarea = MIN (area, minarea); // update} return minarea;} int main () {scanf ("% d ", & T); // while (scanf ("% d", & ply. n), ply. n) for (int Case = 1; Case <= T; ++ Case) {scanf ("% d", & n); ply. n = 4 * n; int I; double area; for (I = 0; I <ply. n; I ++) scanf ("% lf", & ply. p [I]. x, & ply. p [I]. y); sort (ply. p, ply. p + ply. n, cmop); // sort (ply. p + 1, ply. p + ply. n, cmp); ply = graham (); // convex hull if (ply. n <3) area = 0; else area = solve (); printf ("Case # % d: \ n", Case); ans = area + 0.5; printf ("% d \ n", ans);} return 0 ;}