Zoj monthly, February 2012 C, D, F, H

Source: Internet
Author: User
Tags cmath

C: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3573.

You can use the line segment tree + lazy to solve the problem. CB once had a similar process, which can be 0 (n. Subtract the value on the left and calculate the value while walking.

#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.

This question is quite good. Find the intersection of all line segments between two straight lines. The idea at the beginning was to sort the left and right separately and calculate the intersection point based on the difference value, but the sorting seemed to be problematic. Later, I changed it to sorting by the Y value on the right and then finding the reverse order number.

#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

This question is a guess. convert it into two mutually dependent models and calculate the percentage. Multiply the total length by the percentage.

#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 is very small, it can be used to determine the maximum value of the region after each operation, and then H is the total result. Finally, you can find a maximum value.

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.