HZNU Training 6 for Zhejiang Provincial Competition 2020

Solve A B C D E F G H I J K
7/11 Ø Ø    


 

A - A

  CodeForces - 1097B 

 Sign, it is determined whether or not a multiple of 360, DFS solution;

#include<bits/stdc++.h>
using namespace std;
bool flag;
int a[100];
    int n;
void dfs(int pass,int sum){
    if((sum%360==0)&&pass==n){flag=1;return ;}
    
    if(flag||pass==n)return ;
    dfs(pass+1,sum+a[pass+1]);
    dfs(pass+1,sum-a[pass+1]);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    flag=0;
    dfs(1,a[1]);
    if(flag)puts("YES");
    else puts("NO");
    // system("pause");
    return 0;
}
View Code

B - B

 CodeForces - 1144F 

Bare bipartite graph staining, dfs solution, bfs not;

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=2e5+5;
struct edge{int u,v;edge(int a,int b){u=a,v=b;}};
vector<int>e[N];
vector<edge>t;
int color[N];
bool flag;
void dfs(int u,int pass){
    color[u]=pass;
    if(!flag)return ;
    for(int i=0;i<e[u].size();i++){
    int v=e[u][i];
    if(color[v]<0)dfs(v,1-pass);
    if(color[v]==color[u]){flag=0;return ;}
    }
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)color[i]=-1;
    while(m--){
    int u,v;
    scanf("%d %d",&u,&v);
    e[u].pb(v);e[v].pb(u);
    t.pb(edge(u,v));
    }
    flag=1;
    dfs(1,1);
    if(!flag){puts("NO");return 0;}
    puts("YES");
    string s;
    for(int i=0;i<t.size();i++){
    if(color[t[i].u]==1)s+='1';
    else s+='0';
    }
    cout<<s<<endl;
    // system("pause");
    return 0;
}
View Code

C - C

 CodeForces - 1110E 

Stay pit

D - D

 CodeForces - 659D 

Two solutions;

Solution 1: dwell on; four cases;

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define pb push_back
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=1e5+5;
struct point{int x, y;}P[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d %d",&P[i].x,&P[i].y);
    int ans=0;
    for(int i=2;i<n;i++){
    if(P[i].y==P[i-1].y&&P[i].x>P[i-1].x&&P[i+1].x==P[i].x&&P[i+1].y>P[i].y)ans++;
    else if(P[i].x==P[i-1].x&&P[i].y>P[i-1].y&&P[i].y==P[i+1].y&&P[i].x>P[i+1].x)ans++;
    else if(P[i].y==P[i-1].y&&P[i].x<P[i-1].x&&P[i+1].x==P[i].x&&P[i].y>P[i+1].y)ans++;
    else if(P[i].x==P[i-1].x&&P[i].y<P[i-1].y&&P[i].y==P[i+1].y&&P[i].x<P[i+1].x)ans++;
    }
    printf("%d\n",ans);
    // system("pause");
    return 0;
}
View Code

 

 

 Solution II: The above observation image, b will be in a counterclockwise direction, the cross-product can be determined;

 

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++)
#define per(i,j,k) for(int i=(int)k;i>=(int)j;i++)
#define pb push_back
using namespace std;
typedef long long ll;
const int N=1e3+5;
const double eps=1e-8;
// struct Point{int x,y;}P[N];
struct point{
    int x,y;
    point(){}
    point(int a,int b):x(a),y(b){}
    // point(int a,int b){x=a,y=b;}
}P[N];
point Vector(point a,point b){return point(b.x-a.x,b.y-a.y);}
// int dot(point a,point b){}
int main(){
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)scanf("%d %d",&P[i].x,&P[i].y);
    for(int i=2;i<n;i++){
    point a=Vector(P[i-1],P[i]);
    point b=Vector(P[i],P[i+1]);
    if((a.x*b.y-a.y*b.x)>0)ans++;
    }
    cout<<ans<<endl;
    // system("pause");
    return 0;
}
View Code

E - E

 Happening - 2972 

Stay pit;

I - I

 POJ - 1703 

Attendance;

#include<cstdio>
using namespace std;
const int maxn=1e6+5;
int fa[maxn];
int find(int x){
    if(x==fa[x])return x;
    else 
    return fa[x]=find(fa[x]);
//    return fa[x]==x?x:find(fa[x]);
}
void build(int x,int y){
    int dx=find(x);
    int dy=find(y);
    fa[dx]=dy;
}
int main(){
    int t,n,m;
    scanf("%d",&t);
    while(t--){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=2*n;i++)fa[i]=i;
    char op;
    int x,y;
    while(m--){
        getchar();
    scanf("%c%d%d",&op,&x,&y);
    if(op=='D'){
    build(x,and +n);
    build(x+n,y);
    }
    else {
    if(find(x)==find(y+n))
    printf("In different gangs.\n");
    else if(find(x)==find(y))
    printf("In the same gang.\n");
    else 
    printf("Not sure yet.\n");
    }
            }
    }
    return 0;
}
View Code

 

 

Guess you like

Origin www.cnblogs.com/littlerita/p/12466629.html