7.17
HDU 5456 Matches Puzzle Game
没有最丑只有更丑。
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 typedef long long LL; 7 int num[] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; 8 LL dp[555][2][2][2][2]; 9 10 int main(void) 11 { 12 int T; 13 scanf("%d", &T); 14 for(int kase = 1; kase <= T; kase++) 15 { 16 LL n, m; 17 scanf("%I64d %I64d", &n, &m); 18 memset(dp, 0, sizeof(dp)); 19 dp[n-3][0][0][0][0] = 1; 20 for(int i = n - 3; i > 0; i--) 21 { 22 for(int p1 = 0; p1 <= 1; p1++) 23 for(int p2 = 0; p2 <= 1; p2++) 24 for(int p3 = 0; p3 <= 1; p3++) 25 for(int k = 0; k <= 1; k++) 26 for(int a = 0; a <= 9; a++) 27 for(int b = 0; b <= 9; b++) 28 { 29 if(p1 || p2 && b) continue; 30 31 int c = a - k - b, nk = 0; 32 if(c < 0) c += 10, nk = 1; 33 if(p3 && c) continue; 34 35 int tot = num[a]; 36 if(!p2) tot += num[b]; 37 if(!p3) tot += num[c]; 38 if(tot > i) continue; 39 40 for(int pp1 = 0; pp1 <= 1; pp1++) 41 for(int pp2 = 0; pp2 <= 1; pp2++) 42 for(int pp3 = 0; pp3 <= 1; pp3++) 43 { 44 if(p1 && !pp1) continue; 45 if(p2 && !pp2) continue; 46 if(p3 && !pp3) continue; 47 if(pp1 && !(a && !nk)) continue; 48 if(!p2 && pp2 && !b) continue; 49 if(!p3 && pp3 && !c) continue; 50 if(pp1 && !pp2) continue; 51 if(pp1 && !pp3) continue; 52 dp[i-tot][pp1][pp2][pp3][nk] = (dp[i-tot][pp1][pp2][pp3][nk] + dp[i][p1][p2][p3][k]) % m; 53 } 54 } 55 } 56 57 printf("Case #%d: %I64d\n", kase, dp[0][1][1][1][0]); 58 59 } 60 return 0; 61 }
7.18
HDU 5489 Removed Interval
一个BIT可以用三遍西西西
1 #include2 #include 3 #include 4 #include 5 #include
HDU 5517 Triple
好久不见二维树状数组哦。
现已加入豪华午餐。
1 #include2 #include 3 #include 4 #include 5 #include
昨天BC2周年没打。补个题。
1004平面最近点对没做过。顺便A了个板子题。
HDU 1007 Quoit Design
#include#include #include #include #include using namespace std; const int maxn = 1e5 + 10; const double INF = 1e18; struct point { double x, y; } p[maxn]; bool cmpx(point A, point B) { return A.x < B.x; } bool cmpy(point A, point B) { return A.y < B.y; } double dis(point A, point B) { return sqrt((A.x - B.x) * (A.x - B.x) +(A.y - B.y) * (A.y - B.y)); } double cal(int l, int r) { double d = INF; if(l == r) return d; if(l + 1 == r) return dis(p[l], p[r]); int mid = (l + r) >> 1; double d1 = cal(l, mid), d2 = cal(mid + 1, r); d = min(d1, d2); vector v; for(int i = l; i <= r; i++) if(abs(p[mid].x - p[i].x) < d) v.push_back(p[i]); sort(v.begin(), v.end(), cmpy); int sz = v.size(); for(int i = 0; i < sz; i++) { for(int j = i + 1; j < sz; j++) { if(v[j].y - v[i].y >= d) break; d = min(d, dis(v[i], v[j])); } } return d; } int main(void) { int N; while(~scanf("%d", &N) && N) { for(int i = 1; i <= N; i++) scanf("%lf %lf", &p[i].x, &p[i].y); sort(p + 1, p + 1 + N, cmpx); printf("%.2f\n", cal(1, N) / 2); } return 0; }
HDU 5718 Oracle
最近比较背。于是简单题也写了。
1 #include2 #include 3 #include 4 using namespace std; 5 const int maxn = 1e7 + 10; 6 char s[maxn]; 7 int cnt[10]; 8 9 int main(void) 10 { 11 int T; 12 scanf("%d", &T); 13 while(T--) 14 { 15 scanf("%s", s); 16 int l = strlen(s); 17 18 memset(cnt, 0, sizeof(cnt)); 19 for(int i = 0; i < l; i++) cnt[s[i]-'0']++; 20 21 int c = 0; 22 for(int i = 1; i <= 9; i++) c += cnt[i]; 23 if(c < 2) {puts("Uncertain"); continue;} 24 25 int p = 0; 26 for(int i = 1; i <= 9; i++) 27 if(cnt[i]) {cnt[i]--, p = i; break;} 28 29 int pos = 0; 30 for(int i = 0; i <= 9; i++) 31 while(cnt[i]--) s[pos++] = i + '0'; 32 s[pos] = '0'; 33 34 s[0] += p; 35 for(int i = 0; i < pos; i++) 36 if(s[i] > '9') s[i] -= 10, s[i+1]++; 37 38 if(s[pos] != '0') pos++; 39 40 for(int i = pos - 1; i >= 0; i--) printf("%c", s[i]); 41 puts(""); 42 43 } 44 45 return 0; 46 }
HDU 5719 Arrange
无解情况比较多。
1 #include2 #include 3 using namespace std; 4 typedef long long LL; 5 const LL mod = 998244353; 6 const int maxn = 1e5 + 10; 7 int B[maxn], C[maxn]; 8 9 int main(void) 10 { 11 int T; 12 scanf("%d", &T); 13 while(T--) 14 { 15 int n; 16 scanf("%d", &n); 17 for(int i = 1; i <= n; i++) scanf("%d", B + i); 18 for(int i = 1; i <= n; i++) scanf("%d", C + i); 19 20 LL ans = 1; 21 if(B[1] != C[1]) ans = 0; 22 for(int i = 2; i <= n; i++) 23 { 24 if(B[i] > B[i-1]) ans = 0; 25 if(C[i] < C[i-1]) ans = 0; 26 if(B[i] != B[i-1] && C[i] != C[i-1]) ans = 0; 27 } 28 29 for(int i = 2; i <= n; i++) 30 { 31 if(B[i] != B[i-1] || C[i] != C[i-1]) continue; 32 LL tmp = C[i] - B[i] - i + 2; 33 if(tmp <= 0) ans = 0; 34 else ans = ans * tmp % mod; 35 } 36 37 printf("%I64d\n", ans); 38 39 } 40 41 return 0; 42 }
HDU 5720 Wool
喜欢无脑丢set。
1 #include2 #include 3 #include 4 #include <set> 5 using namespace std; 6 typedef long long LL; 7 typedef pair pii; 8 const int maxn = 1e5 + 10; 9 LL a[maxn]; 10 set S; 11 set ::iterator it; 12 13 int main(void) 14 { 15 int T; 16 scanf("%d", &T); 17 while(T--) 18 { 19 S.clear(); 20 int n; 21 LL L, R; 22 scanf("%d %I64d %I64d", &n, &L, &R); 23 for(int i = 1; i <= n; i++) scanf("%I64d", a + i); 24 sort(a + 1, a + 1 + n); 25 for(int i = 2; i <= n; i++) 26 { 27 if(a[i] - a[i-1] + 1 > R || a[i] + a[i-1] - 1 < L) continue; 28 LL l = max(L, a[i] - a[i-1] + 1), r = min(R, a[i] + a[i-1] - 1); 29 S.insert(pii(l, r)); 30 } 31 32 LL ans = R - L + 1, tmp = 0; 33 for(it = S.begin(); it != S.end(); it++) 34 { 35 LL l = (*it).first, r = (*it).second; 36 if(r <= tmp) continue; 37 if(l <= tmp) ans -= r - tmp; 38 else ans -= r - l + 1; 39 tmp = r; 40 } 41 42 printf("%I64d\n", ans); 43 44 } 45 return 0; 46 }
HDU 5721 Palace
删点就换了个无穷远点。
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 typedef long long LL; 7 const int maxn = 1e5 + 10; 8 const LL INF = 1e18; 9 10 struct point 11 { 12 int id; 13 LL x, y; 14 } p[maxn]; 15 16 bool cmpx(point A, point B) 17 { 18 return A.x < B.x; 19 } 20 21 bool cmpy(point A, point B) 22 { 23 return A.y < B.y; 24 } 25 26 LL dis(point A, point B) 27 { 28 return (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y); 29 } 30 31 LL m; 32 point p1, p2; 33 LL cal(int l, int r) 34 { 35 LL d = INF; 36 if(l == r) return d; 37 if(l + 1 == r) 38 { 39 d = dis(p[l], p[r]); 40 if(d < m) p1 = p[l], p2 = p[r], m = d; 41 return d; 42 } 43 44 int mid = (l + r) >> 1; 45 LL d1 = cal(l, mid), d2 = cal(mid + 1, r); 46 d = min(d1, d2); 47 48 vector v; 49 for(int i = l; i <= r; i++) 50 if((p[mid].x - p[i].x) * (p[mid].x - p[i].x) < d) 51 v.push_back(p[i]); 52 sort(v.begin(), v.end(), cmpy); 53 54 int sz = v.size(); 55 for(int i = 0; i < sz; i++) 56 { 57 for(int j = i + 1; j < sz; j++) 58 { 59 if((v[j].y - v[i].y) * (v[j].y - v[i].y) >= d) break; 60 d = min(d, dis(v[i], v[j])); 61 if(d < m) m = d, p1 = v[i], p2 = v[j]; 62 } 63 } 64 65 return d; 66 } 67 68 int main(void) 69 { 70 int T; 71 scanf("%d", &T); 72 while(T--) 73 { 74 int N; 75 scanf("%d", &N); 76 for(int i = 1; i <= N; i++) scanf("%I64d %I64d", &p[i].x, &p[i].y); 77 sort(p + 1, p + 1 + N, cmpx); 78 for(int i = 1; i <= N; i++) p[i].id = i; 79 80 m = INF; 81 LL ans = cal(1, N) * (N - 2); 82 point M; 83 M.x = M.y = 1e8; 84 int a = p1.id, b = p2.id; 85 swap(M, p[a]); 86 ans = ans + cal(1, N); 87 swap(M, p[a]); 88 swap(M, p[b]); 89 ans = ans + cal(1, N); 90 91 printf("%I64d\n", ans); 92 93 } 94 return 0; 95 }
HDU 5722 Jewelry
想了半天整数扫描线怎么搞……其实浮点数的板,右端点+1就可以了。
1 #include2 #include 3 #include 4 #include