20190817

EX1 flip game

As shown, there is a 4 x 4 checkerboard. Each may operate one piece, the piece itself and its four directions around the pieces (if present) will be inverted, i.e. from black to white inverted from white to black. At least ask how many steps need to be able to make all the pieces have become the same color.

[Enter]

The output of the matrix of 4 * 4, W represents white, b represents black, other characters do not appear.

[Output]

Only output line, comprising a minimum number of steps are asking.


 

Hey, equal to 4, even if I found it 2 ^ 16 = 65536

What would like to see me out of the violence took him A

#include<bits/stdc++.h>
#define re return
#define inc(i,l,r) for(int i=l;i<=r;++i)
using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=1;
    x=c^48;
    while((c=getchar())>='0'&&c<='9')x=x*10+(c^48);
    if(f)x=-x;
}

int dx[6]={0,0,1,-1,0,0},dy[6]={0,0,0,0,1,-1};
int n,m,col[10][10],vis[10];
int ans=17;

inline void DFS ( int x, int y, int I) 
{ 
    
    if (a> = ans) n; 
    
    to [ 0 ] = 0 , the force [ 1 ] = 1 ; 
    Inc (I, 1 , 4 ) Heating (s, 1 , 4 ) force [col [i] [j]] = 1 ;
    if (! force [ 0 ] || (! force [ 1 ])) 
    { 
        ans = I; n; 
    } 
    
    Int flag = 1 , J; 
    inc (i, x, 4)
    {
         if(flag)flag=0,j=y+1;
         else j=1;
        for(j;j<=4;++j)
        {
            inc(k,1,5)
            {
                int nx=i+dx[k],ny=j+dy[k];
                if(nx<1||ny<1||nx>4||ny>4)continue;
                col[nx][ny]^=1; 
            }
            dfs(i,j,sum+1);
            inc(k,1,5)
            {
                int nx=i+dx[k],ny=j+dy[k];
                if(nx<1||ny<1||nx>4||ny>4)continue;
                col[nx][ny]^=1; 
            }
        }
        
    }
}
int main()
{
     char ss[10];
    inc(i,1,4)
    {
        scanf("%s",ss+1);
        inc(j,1,4)
        if(ss[j]=='b')col[i][j]=1;
        else col[i][j]=0;
    }
    
    dfs(0,4,0);
    
    if(ans==17)printf("Impossible");
    else printf("%d",ans);
    re 0;
} 

Hey, how only 80

 

       view [ 0 ] = 0 , show [ 1 ] = 1 ;

Think of the scared, I still have 80? ? ?

How water data, people have more water

EX2 islands

Once there is an island, the island is a rectangular, square area is designated as N * M, and each region has a certain height. Unfortunately, the sea level began to rise in the first year i, sea level is t [i]. If the height of a region is less than equal to sea level, it is considered to be submerged. Those communication areas not be submerged into a communication block. Now asking i year, so how many of the communication block. For example: the first year sea level 1, there are two communication blocks. Second year sea level is 2, there are three communication blocks.image

[Enter]

The first line contains two numbers N, M.

Next is a N * M matrix, the i-th row j-th column of the grid represents the height H [i] [j]

T followed by a number, expressed T days,

The last line number of the T, and i denotes the i-th day the number of water level. (Guaranteed to be increasing)

[Output]

Output contains a line number T, and i represents the number of i-th number of connected blocks day.


 

Communication block? Disjoint-set of the likelihood.

cut the relation between a and b

Backwards to do just fine

Wait a minute, this data range 9 million?

Forget it

Card about space, manual calculation

Just write to write, it took a long time to manually

Ah, I must be right

80?

nmggo

what happened again

The first set of data even with the tenth set of data is the same small data

I actually all wrong

Looked, did not maintain the legitimacy of the number of days of flashback

qaq

A lot of small details

#include<bits/stdc++.h>
#define re return
#define dec(i,l,r) for(int i=l;i>=r;--i) 
#define inc(i,l,r) for(int i=l;i<=r;++i)
using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=1;
    x=c^48;
    while((c=getchar())>='0'&&c<='9')x=x*10+(c^48);
    if(f)x=-x;
}

const int maxn=3005,maxt=100005;
int n,m,T,t[maxt],ans[maxt],fa[maxn*maxn];

int dx[5]={0,0,0,1,-1},dy[5]={0,1,-1,0,0};
struct node{
    int x,val;
    bool operator<(node a)const
    {
        re val>a.val;
    }
}a[maxn*maxn];


inline int find(int x)
{
    re x==fa[x]?x:fa[x]=find(fa[x]);
}
int main()
{
    rd(n);rd(m);
    inc(i,1,n)
    {
        int v=(i-1)*m;
        inc(j,1,m)
        {
            rd(a[v+j].val);
            a[v+j].x=v+j;
        }
    }
    
    rd(T);
    inc(i,1,T)
    rd(t[i]);
    
    sort(a+1,a+n*m+1);
    int j=T;
    for(int i=1;i<=n*m;++i)
    {
        int f=0;
        while(a[i].val<=t[j])
        {
            --j;
            if(!j)
            {
                f=1;
                break;
             } 
    //就是这个地方 ans[j]
=ans[j+1]; } if(f)break; ++ans[j]; fa[a[i].x]=a[i].x; int y=a[i].x%m; if(!y)y=m; int x=(a[i].x-y)/m+1; for(int k=1;k<=4;++k) { int nx=(x+dx[k]),ny=y+dy[k]; if(nx<1||ny<1||nx>n||ny>m)continue; nx=(nx-1)*m+ny; if(!fa[nx])continue; int f1=find(a[i].x),f2=find(nx); if(f1!=f2) { --ans[j]; fa[f1]=f2; } } } dec(k,j-1,1)ans[k]=ans[j]; inc(i,1,T) printf("%d ",ans[i]); re 0; }

Wu mate EX3 God's choice

【Problem Description】

Wu God most often do one thing, in his bedroom, looking up at the white ceiling, lonely empty Dan Yiqu Oriental wedding night.

Wu has become the God of God, there are countless fans, there are some Momoaimu his Lolita is too small, but these people Wu God can not become the other half of God Wu (Wu God expressed their principles, not because do not see on others), although it has long been the talk of marriage age, Wu God is alone in the world.

Wu God like philosophy, but does not exclude heterosexual. Bored, take a look at the training team who is and who is more suitable, Wu became God's way of killing time.

In the eyes of God Wu, everyone has different advantages, such as high, rich, handsome, Wu God .... These advantages are quantized into a binary number, each bit represents an advantage whether in person body exists, God Wu believes that two people should not have the advantage of intersection, otherwise it is a waste !! this focus on the efficiency of God Wu is determined not allowed. advantages such as diligently can be expressed as ( 1011010 ) (1011010), uniform uniform can be expressed as (0,100,100), (1011010) & (0,100,100) == 0 (0,100,100), (1011010) & (0,100,100) == 0 (no intersection), so in the eyes of God Wu Yunhe uniform is diligently suitable Wu God is ( 11111 ...... 111111 ) (11111 ...... 111111), so Wu God and no one is inappropriate, because no one is no advantage.

Now Wu God have to do it is: According to the characteristic value of each person, find people with the right people n the personal given, if there are multiple output features that a maximum value, a person may be more than one person pairing. If not, 0 is output.

[Enter]

A first row of n represents the total number of the second row is the number n, each represents feature values ​​ai

[Output]

The maximum value of the output characteristic line contains the number N, corresponding to the right person for everyone


 

Hit the table, dp, find the law

Ghost yo!

First called n ^ 2 violence, but also called full of thought right dfs;

Shot will find dfs, yet I am almost violent

Well, pay out of violence, even water to 90pts

Correct

Zhengnanzefan

For a number a, if 1111111111 ...... ^ a = b;

And b | c = b;

We can think of a & c = 0

Then you traverse fucks it, you have almost a

#include<bits/stdc++.h>
#define re return
#define inc(i,l,r) for(int i=l;i<=r;++i)
using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=1;
    x=c^48;
    while((c=getchar())>='0'&&c<='9')x=x*10+(c^48);
    if(f)x=-x;
}

int a[1500005],b[1500005];
//a表示原数,b表示包含b[i]的数
 
int main()
{
    freopen("in.txt","r",stdin);
    int n,maxx=0;
    rd(n);
    inc(i,1,n)
    {
        rd(a[i]);
        maxx=max(a[i],maxx);
        b[a[i]]=a[i];
        //存在,初始化 
    }
    
    int cnt=0;
    while((1<<cnt)<=maxx)++cnt;
    
    
    
    inc(i,0,(1<<cnt))
    {
        inc(x,0,cnt)
        if(!((1<<x)&i))
        b[i|(1<<x)]=max(b[i|(1<<x)],b[i]);
        //最大可行解 
    }
    
    inc(i,1,n)
    printf("%d ", B [((1CNT <<) - . 1 ) ^ A [I]]);
     // inversion 
    Re 0 ; 
}

 

Guess you like

Origin www.cnblogs.com/lsyyy/p/11368948.html
Recommended