Codeforces Round #291 (Div. 2) Problem Solving report A. B .C.D. E,

Source: Internet
Author: User
Tags acos

Codeforces Round #291 (Div. 2) Problem Solving report A. B .C.D. E,

A-Chewba certificate ca and Number
If the value is greater than 4, the value is not greater than or equal to 4. Note that if the first digit is 9, the system does not invert the image.
The Code is as follows:

#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL long long#define pi acos(-1.0)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-9;char s[100];int main(){        int len, i;        scanf("%s",s);        len=strlen(s);        for(i=0;i<len;i++){                if(!(s[i]=='9'&&i==0)&&s[i]>'4')                        s[i]=9-(s[i]-'0')+'0';        }        printf("%s\n",s);        return 0;}

B-Han Solo and Lazer Gun
Traverse and mark the points in the same straight line. Pay attention to the accuracy.
The Code is as follows:

#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL long long#define pi acos(-1.0)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-12;int vis[2000];struct node{        int x, y;}fei[2000];int main(){        int n, x0, y0, i, j, flag=0, ans;        double k, b;        scanf("%d%d%d",&n,&x0,&y0);        for(i=0;i<n;i++){                scanf("%d%d",&fei[i].x,&fei[i].y);        }        memset(vis,0,sizeof(vis));        for(i=0;i<n;i++){                if(fei[i].x==x0){                        vis[i]=1;                        flag=1;                }        }        ans=flag;        for(i=0;i<n;i++){                if(!vis[i]){                        vis[i]=1;                        k=(double)(y0-fei[i].y)/(x0-fei[i].x);                        b=y0-k*x0;                        for(j=0;j<n;j++){                                if(vis[j]) continue ;                                if(fabs(fei[j].y*1.0-(k*fei[j].x+b))<eqs){                                        vis[j]=1;                                }                        }                        ans++;                }        }        printf("%d\n",ans);        return 0;}

C-Watto and Mechanic
This question is so miserable .. The map used directly for the first time is hack .. In addition, hash is added, and the final test result is suspended .. It should be a string hash write failure .. I did not expect a better hash method. So I changed it to the dictionary tree + dfs ..
The Code is as follows:

#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL long long#define pi acos(-1.0)#define ULL unsigned long longconst int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-12;char str[610000];struct node{        int flag;        node *next[4];};node *newnode(){        int i;        node *p=new node;        p->flag=0;        for(i=0;i<3;i++){                p->next[i]=NULL;        }        return p;}void build(node *root, char *s){        int i, x, len=strlen(s);        node *p=root;        for(i=0;i<len;i++){                x=s[i]-'a';                if(p->next[x]==NULL){                        p->next[x]=newnode();                }                p=p->next[x];        }        p->flag=1;}bool dfs(node *p, char *s, int len, int flag, int maxd){        int i;        if(len==maxd){                if(flag&&p->flag) return 1;                return 0;        }        for(i=0;i<3;i++){                if(p->next[i]==NULL) continue ;                if(i!=s[len]-'a'){                        if(flag) continue ;                        if(dfs(p->next[i],s,len+1,1,maxd))                                return 1;                }                else{                        if(dfs(p->next[i],s,len+1,flag,maxd)) return 1;                }        }        return 0;}int main(){        int n, m, len;        scanf("%d%d",&n,&m);        node *root=newnode();        while(n--){                scanf("%s",str);                build(root,str);        }        while(m--){                scanf("%s",str);                len=strlen(str);                if(dfs(root,str,0,0,len))                        puts("YES");                else puts("NO");        }        return 0;}

D-R2D2 and Droid Army
Questions... During the competition, I had been entangled in question C. I have no idea about this question .. The result is A in 20 minutes .. Sad ..
The general idea is double pointer + line segment tree.
Since it is the longest interval problem, we can instantly think of double pointers. Then, you can determine whether the maximum value in the interval meets the conditions. The maximum query value is obviously maintained by the line segment tree. M is 5 at the maximum, so m line segments can be maintained at the same time.
The Code is as follows:

#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL long long#define pi acos(-1.0)#define ULL unsigned long longconst int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-12;const ULL B=1e9+7;#define root 0, n-1, 1#define lson l, mid, rt<<1#define rson mid+1, r, rt<<1|1int Max[6][400000], q_max[6], m, ans[6];void PushUp(int f, int rt){        Max[f][rt]=max(Max[f][rt<<1],Max[f][rt<<1|1]);}void Update(int f, int p, int x, int l, int r, int rt){        if(l==r){                Max[f][rt]=x;                return ;        }        int mid=l+r>>1;        if(p<=mid) Update(f,p,x,lson);        else Update(f,p,x,rson);        PushUp(f,rt);}void Query(int ll, int rr, int l, int r, int rt){        if(ll<=l&&rr>=r){                for(int i=0;i<m;i++){                        q_max[i]=max(q_max[i],Max[i][rt]);                }                return ;        }        int mid=l+r>>1;        if(ll<=mid) Query(ll,rr,lson);        if(rr>mid) Query(ll,rr,rson);}int main(){        int n, k, i, j, max1, l, r, x, flag;        LL sum;        scanf("%d%d%d",&n,&m,&k);        for(i=0;i<n;i++){                for(j=0;j<m;j++){                        scanf("%d",&x);                        Update(j,i,x,root);                }        }        l=r=max1=0;        for(r=0;r<n;r++){                flag=0;                while(!flag){                        memset(q_max,-1,sizeof(q_max));                        Query(l,r,root);                        sum=0;                        for(i=0;i<m;i++){                                sum+=q_max[i];                        }                        if(sum<=k) flag=1;                        else l++;                }                if(max1<r-l+1){                        memcpy(ans,q_max,sizeof(ans));                        max1=r-l+1;                }        }        for(i=0;i<m;i++){                printf("%d ",ans[i]);        }        return 0;}

E-Darth Vader and Tree
For more information, see this blog portal E-Darth Vader and Tree.

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.