11.14 Arts Comprehensive Examination

11.14 Arts Comprehensive Examination

Science comprehensive test in others, we in Covent comprehensive

T1 history

will not.

#include<bits/stdc++.h>
#define int long long
char buf[1<<20],*p1,*p2;
#define uc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
#define ph putchar
using namespace std;
const int inf=1e9+7;
inline int in();
inline void out(int x);
int a=in(),k=in(),m=in(),mky,ax,lx=-1,lyr,ayr=-1;
int hea[10000010],lst[10000010],ext[10000010];
bool bkl[10000010],oier;
main(void) {
    register int i,mu;
    for(i=0; i<k; i++) {
        mky=i*i%k;
        if(!bkl[mky]) {
            bkl[mky]=1;
            hea[mky]=i;
        } else ext[lst[mky]]=i;
        lst[mky]=i,ext[i]=-1;
    }   register int qt,rt;
    while(a) {
        if(!bkl[a%k]) {
            ax=-1;
            if(!oier&&m>=a&&(m-a)%k==0)
                ayr=lyr+(m-a)/k;
            break;
        }   qt=ceil(sqrt(a)),mu=qt%k;
        for(i=hea[a%k]; i>=0; i=ext[i])
            if(i>=mu)break;
        if(i<0)i=hea[a%k]+k;
        qt+=i-mu,rt=qt*qt;
        if(!oier&&m>=a&&m<=rt&&(m-a)%k==0)
            ayr=lyr+(m-a)/k,oier=1;
        if(lx==rt)break;
        lyr+=(rt-a)/k+1,a=qt;
        ax=max(ax,rt),lx=rt;
    }   out(ax),ph('\n'),out(ayr);
}
inline int in() {
    register int x=0;
    register char s=uc;
    register bool f=0;
    while((s<'0'||s>'9')&&s!='-')s=uc;
    if(s=='-')f=1,s=uc;
    while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+(s^48),s=uc;
    return f?-x:x;
}
inline void out(int x) {
    if(x<0)ph('-'),x=~x+1;
    if(x>9)out(x/10);
    ph((x%10)^48);
}

T2 Geography

The only made out of the question.Could it be that this indicates that the selection of subjects to choose my geography?

Title effect:
given a (N * N * N \) \ cube, the cube represent obstacles 0, 1 represents the ground, from the ground to \ (1s / \) went to a four-frame adjacent grid speed. May be transferred to another surface along the edge. Exist \ (m \) a wormhole, from the point \ (lS \) to the other point.
There \ (Q \) once asked, ask it went the other point of the shortest time. If you can not reach the output \ (--1 \) .

Data range:
\ (. 1 \ Leq N \ leq10,0 \ Leq m \ Leq 1000,1 \ Leq Q \ ^. 5 Leq 10 \)
do not work the problem difficult to see.
This question is really very simple.
Really.

\ (Qaq \)


In fact, \ (BFS \) After that, it seems to be able to reach the edges to link \ (Floyd \) also run.
Note To ask first before all counted out several programs, for insurance with a 6-dimensional array of memory answer.
Really it is \ (BFS \) only.
Only.
Really

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int n;
bool Map[7][12][12];//1:U 2:L 3:F 4:R 5:B 6:D 
inline int sel(char x){switch(x){case 'U':{return 1;}case 'L':{return 2;}case 'F':{return 3;}case 'R':{return 4;}case 'B':{return 5;}case 'D':{return 6;}}}
struct cd{
    int sum;
    int to1[601],tox[601],toy[601];
    bool ap;
}map1[7][12][12];
char T[100];
bool mark[7][12][12];
int dis[7][12][12][7][12][12];
struct node{
    int pm,x,y;
    int dis;
};
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};

node change(int p,int x,int y)
{
    node tmp;
    switch(p){
        case 1:{
            if(x==0){
                tmp.pm=4;
                tmp.x=1;
                tmp.y=n-y+1;
            }
            if(x==n+1){
                tmp.pm=2;
                tmp.x=1;
                tmp.y=y;
                
            }
            if(y==0){
                tmp.pm=5;
                tmp.x=1;
                tmp.y=x;
            }
            if(y==n+1){
                tmp.pm=3;
                tmp.x=1;
                tmp.y=n-x+1;
            }
            return tmp;
            break;
        }
        case 2:{
            if(x==0){
                tmp.pm=1;
                tmp.x=n;
                tmp.y=y;
            }
            if(x==n+1){
                tmp.pm=6;
                tmp.x=1;
                tmp.y=y;
            }
            if(y==0){
                tmp.pm=5;
                tmp.x=x;
                tmp.y=n;
            }
            if(y==n+1){
                tmp.pm=3;
                tmp.x=x;
                tmp.y=1;
            }
            return tmp;
            break;
        }
        case 3:{
            if(x==0){
                tmp.pm=1;
                tmp.x=n-y+1;
                tmp.y=n;
            }
            if(x==n+1){
                tmp.pm=6;
                tmp.x=y;
                tmp.y=n;
            }
            if(y==0){
                tmp.pm=2;
                tmp.x=x;
                tmp.y=n;
            }
            if(y==n+1){
                tmp.pm=4;
                tmp.x=x;
                tmp.y=1;
            }
            return tmp;
            break;
        }
        case 4:{
            if(x==0){
                tmp.pm=1;
                tmp.x=1;
                tmp.y=n-y+1;
            }
            if(x==n+1){
                tmp.pm=6;
                tmp.x=n;
                tmp.y=n-y+1;
            }
            if(y==0){
                tmp.pm=3;
                tmp.x=x;
                tmp.y=n;
            }
            if(y==n+1){
                tmp.pm=5;
                tmp.x=x;
                tmp.y=1;
            }
            return tmp;
            break;
        }
        case 5:{
            if(x==0){
                tmp.pm=1;
                tmp.x=y;
                tmp.y=1;
            }
            if(x==n+1){
                tmp.pm=6;
                tmp.x=n-y+1;
                tmp.y=1;
            }
            if(y==0){
                tmp.pm=4;
                tmp.x=x;
                tmp.y=n;
            }
            if(y==n+1){
                tmp.pm=2;
                tmp.x=x;
                tmp.y=1;
            }
            return tmp;
            break;
        }
        case 6:{
            if(x==0){
                tmp.pm=2;
                tmp.x=n;
                tmp.y=y;
            }
            if(x==n+1){
                tmp.pm=4;
                tmp.x=n;
                tmp.y=n-y+1;
            }
            if(y==0){
                tmp.pm=5;
                tmp.x=n;
                tmp.y=n-x+1;
            }
            if(y==n+1){
                tmp.pm=3;
                tmp.x=n;
                tmp.y=x;
            }
            return tmp;
            break;
        }
    }
}
int bfs(int sp,int sx,int sy)
{
    memset(mark,0,sizeof(mark));
    queue<node>q;
    q.push((node){sp,sx,sy,0}); 
    while(q.size()){
        node tmp=q.front();
        int p=tmp.pm,x=tmp.x,y=tmp.y;
        q.pop();
        if(mark[p][x][y])continue;
        mark[p][x][y]=1;
        dis[sp][sx][sy][p][x][y]=tmp.dis;
        for(int i=0;i<4;i++){
            int fx=x+dx[i],fy=y+dy[i];
            if(fx==0||fx==n+1||fy==0||fy==n+1){
                node p1=change(p,fx,fy);
                if(!Map[p1.pm][p1.x][p1.y])continue;
                p1.dis=tmp.dis+1;
                q.push(p1);
            }
            else{
                node p2;
                if(!Map[p][fx][fy])continue;
                p2.pm=p;p2.x=fx;p2.y=fy;p2.dis=tmp.dis+1;
                q.push(p2);
            }
            
        }
        if(map1[p][x][y].ap){
            cd t=map1[p][x][y];
            for(int i=1;i<=t.sum;i++)
            {
                node p3;
            p3.pm=t.to1[i];p3.x=t.tox[i];p3.y=t.toy[i];p3.dis=tmp.dis+1;
            if(!Map[p3.pm][p3.x][p3.y])continue;
            q.push(p3);
            }
        }
    }
}
int main()
{
    memset(dis,0x3f,sizeof(dis));
    ios::sync_with_stdio(0);
    cin.tie(0);
//  freopen("geog.in","r",stdin);
//  freopen("geog.out","w",stdout);
    int i,j;
    cin>>n;
    for(i=1;i!=n+1;++i){
        cin>>T;
        for(j=1;j!=n+1;++j){
            Map[1][i][j]=T[j-1]-'0';
        }
    }
    for(i=1;i!=n+1;++i)
    {
        cin>>T;
        for(j=1;j!=4*n+1;++j){
            Map[1+(j-1)/n+1][i][(j-1)%n+1]=T[j-1]-'0';
        }
    }
    for(i=1;i!=n+1;++i){
        cin>>T;
        for(j=1;j!=n+1;++j){
            Map[6][i][j]=T[j-1]-'0';
        }
    }
    int m;
    cin>>m;
    for(i=1;i<=m;++i)
    {
        char f1,f2;
        int x1,y1,x2,y2;
        cin>>f1>>x1>>y1>>f2>>x2>>y2;
        int ff1=sel(f1),ff2=sel(f2);
        map1[ff1][x1][y1].sum+=1;map1[ff2][x2][y2].sum+=1;
        map1[ff1][x1][y1].ap=1;map1[ff1][x1][y1].to1[map1[ff1][x1][y1].sum]=ff2;map1[ff1][x1][y1].tox[map1[ff1][x1][y1].sum]=x2;map1[ff1][x1][y1].toy[map1[ff1][x1][y1].sum]=y2;
        map1[ff2][x2][y2].ap=1;map1[ff2][x2][y2].to1[map1[ff2][x2][y2].sum]=ff1;map1[ff2][x2][y2].tox[map1[ff2][x2][y2].sum]=x1;map1[ff2][x2][y2].toy[map1[ff2][x2][y2].sum]=y1;
    }
    for(int p=1;p<=6;p++)
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++){
                if(Map[p][i][j]){
                    bfs(p,i,j);
                }
            }
        }
    }
    int Q;
    cin>>Q;
    for(i=1;i<=Q;++i){
        char f1,f2;
        int x1,y1,x2,y2;
        cin>>f1>>x1>>y1>>f2>>x2>>y2;
        int d=dis[sel(f1)][x1][y1][sel(f2)][x2][y2];
        if(d!=0x3f3f3f3f)
        printf("%d\n",d);
        else printf("-1\n");
    }
    return 0;
}

Plane Operating good trouble ah ah ah ah ah
Note: There may be multiple wormhole at one point, maybe even their own wormhole

T3 political

Did not see, does not
 
 
 
 
sum up:
1. What do you think of this question to test the algorithm, in fact, you want to test a code
2.nodgdNMSL

Guess you like

Origin www.cnblogs.com/cooper233/p/11860999.html