標籤:style blog http io os ar for sp on
C:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3573
瞎搞題,可以用線段樹+lazy過。CB曾經出過一個類似的,可以0(N)的處理。左邊加右邊減,邊走邊算。
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-8#define M 1000100#define LL long long//#define LL long long#define INF 0x3f3f3f#define PI 3.1415926535898const int maxn = 15100;using namespace std;LL f[maxn];LL p[maxn];LL k[maxn];int main(){ int n; while(~scanf("%d",&n)) { int x, y, z; memset(f, 0, sizeof(f)); memset(p, 0, sizeof(p)); memset(k, 0, sizeof(k)); while(~scanf("%d %d %d",&x, &y, &z)) { if(x == -1) break; f[x] += z; p[y+1] -= z; } int lmax; LL Max = -1LL; LL xmax = 0LL; for(int i = 0; i <= n; i++) { xmax += f[i]+p[i]; k[i] = xmax; if(xmax > Max) { Max = xmax; lmax = i; } } int rmax; for(int i = n; i >= 0; i--) { if(k[i] == Max) { rmax = i; break; } } cout<<lmax<<" "<<rmax<<endl; } return 0;}
D:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3574
這道題目感覺挺好的,求在兩個直線之間的所有線段的交點。一開始的想法是左右分別排序根據差值算出交點,但是排序好像有問題。後來改成按右邊的y值排序再求出逆序數就可以了啊。
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <ctime>#include <map>#include <set>#define eps 1e-12///#define M 1000100///#define LL __int64#define LL long long///#define INF 0x7ffffff#define INF 0x3f3f3f3f#define PI 3.1415926535898#define zero(x) ((fabs(x)<eps)?0:x)using namespace std;const int maxn = 30100;LL sum;struct node{ LL y1; LL y2; int id;};node a[maxn], temp[maxn];void Merge(node a[], int l, int mid, int r){ int begin1 = l; int end1 = mid; int begin2 = mid+1; int end2 = r; int k = 0; while(begin1 <= end1 && begin2 <= end2) { if(a[begin1].y1 < a[begin2].y1) { temp[k++] = a[begin1]; begin1++; sum += begin2-(mid+1); } else { temp[k++] = a[begin2]; begin2++; } } while(begin1 <= end1) { temp[k++] = a[begin1]; begin1++; sum += end2-mid; } while(begin2 <= end2) { temp[k++] = a[begin2]; begin2++; } for(int i = l; i <= r; i++) a[i] = temp[i-l];}void MergeSort(node a[], int l, int r){ int mid = (l+r)>>1; if(l < r) { MergeSort(a, l, mid); MergeSort(a, mid+1, r); Merge(a, l, mid, r); }}bool cmp(node a, node b){ return a.y2 < b.y2;}int main(){ LL x1, x2; while(~scanf("%lld %lld",&x1, &x2)) { int n; scanf("%d",&n); if(n == 0) { cout<<1<<endl; continue; } LL k, b; for(int i = 0; i < n; i++) { scanf("%lld %lld",&k, &b); a[i].y1 = k*x1+b; a[i].y2 = k*x2+b; } sort(a, a+n, cmp); sum = 0; MergeSort(a, 0, n-1); cout<<sum+n+1<<endl; } return 0;}
F:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4598
這個題目是瞎猜了一下,把它轉化為兩個互質的模型後求出來百分比,用總的長度乘以百分比就可以了啊。
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-8#define M 1000100#define LL long long//#define LL long long#define INF 0x3f3f3f#define PI 3.1415926535898const int maxn = 30010;using namespace std;int main(){ LL n, m; while(~scanf("%lld %lld",&n, &m)) { double x = sqrt(n*n*1.0+m*m*1.0); LL p = __gcd(n, m); m /= p; n /= p; p = m*n; LL xx = p/2; if(p%2) xx++; double y = (xx*1.0)/p; printf("%.6lf\n",x*y); } return 0;}
H:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3578
n很小可以暴力判斷每次操作之後所在地區的最大值,然後加上h就是總的結果。最後求出一個最大值就可以了。
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-8#define M 1000100#define LL long long//#define LL long long#define INF 0x3f3f3f#define PI 3.1415926535898const int maxn = 15100;using namespace std;struct node{ int h; int H; int a, b, x, y;}f[maxn];bool judge(int x, int y){ if(f[x].x+f[x].a <= f[y].x || f[y].x+f[y].a <= f[x].x) return false; if(f[x].y+f[x].b <= f[y].y || f[y].y+f[y].b <= f[x].y) return false; return true;}int main(){ int n, m, c; while(~scanf("%d %d %d",&n, &m, &c)) { for(int i = 0; i < c; i++) { scanf("%d %d %d %d %d",&f[i].a, &f[i].b, &f[i].h, &f[i].x, &f[i].y); f[i].H = 0; for(int k = 0; k < i; k++) if(judge(i, k)) f[i].H = max(f[i].H, f[k].H); f[i].H += f[i].h; } int Max = -1; for(int i = 0; i < c; i++) Max = max(Max, f[i].H); cout<<Max<<endl; } return 0;}
ZOJ Monthly, February 2012 C,D,F,H