【HDOJ】5203 Rikka with wood sticks
1 /* 1002 */ 2 #include <iostream> 3 #include <string> 4 #include <map> 5 #include <queue> 6 #include <set> 7 #include <stack> 8 #include <vector> 9 #include <algorithm> 10 #include <cstdio> 11 #include <cmath> 12 #include <ctime> 13 #include <cstring> 14 #include <climits> 15 #include <cctype> 16 using namespace std; 17 18 const int maxn = 1e3+5; 19 20 int a[maxn], dis[maxn]; 21 int n, m; 22 23 int main() { 24 int i, j, k; 25 int mx, q; 26 int l1, l2; 27 int x, y, z, s, tmp; 28 __int64 ans; 29 int L, R; 30 31 #ifndef ONLINE_JUDGE 32 freopen("data.in", "r", stdin); 33 freopen("data.out", "w", stdout); 34 #endif 35 36 while (scanf("%d %d", &n, &m) != EOF) { 37 R = -1; 38 L = n+1; 39 ans = 0; 40 for (i=1; i<=m; ++i) { 41 scanf("%d", &a[i]); 42 L = min(a[i], L); 43 R = max(a[i], R); 44 } 45 if (L==1 || R==n) { 46 s = max(L-1, n-R); 47 for (z=1; z<n; ++z) { 48 if (z >= s-z) 49 break; 50 tmp = s-z; 51 L = (tmp-z)/2+1; 52 R = (tmp+z-1)/2; 53 ans += (R-L+1); 54 } 55 printf("%I64d\n", ans); 56 continue; 57 } 58 l1 = L-1; 59 l2 = n-R; 60 z = l1; 61 for (x=1; x<l2; ++x) { 62 y = l2-x; 63 if (x+y>z && y+z>x && z+x>y) 64 ++ans; 65 } 66 z = l2; 67 for (x=1; x<l1; ++x) { 68 y = l1-x; 69 if (x+y>z && y+z>x && z+x>y) 70 ++ans; 71 } 72 printf("%I64d\n", ans); 73 } 74 75 #ifndef ONLINE_JUDGE 76 printf("%d\n", (int)clock()); 77 #endif 78 79 return 0; 80 }