lxs Contest # 120 2020.1.19

https://file.floj.tech/export/nYGAiM5E4Y4e15467bb2

t1 in FIG.

[Title] Italy

FIG undirected given, it is determined whether the dyed color can moderate the two color points different from each edge attached. If you can not find it odd ring after deleting the original is still connected.

【answer】

First find an original spanning tree, black and white coloring adjacent dots of different colors. If the rest of the side is a bipartite graph, you can, otherwise there is an odd ring. dfs point along the way and once again black and white coloring. If the dye can not force the father to jump up jump point to know the opposite, which is odd ring. Otherwise, dyed color output can be.

code show as below:

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
bool pan;
int n,m,last[N],last3[N],size3,st[N],top,size=1,ans[N],ge,last2[N],size2,siz,fa[N],ans1;
int book[N],ji[N<<1];
struct pigu
{
    int dao,ne;
}a[N<<1],b[N<<1],c[N<<1];
inline void lingjiebiao2(int x,int y)
{
    b[++size2].dao=y;
    b[size2].ne=last2[x];
    last2[x]=size2;
}
inline void lingjiebiao(int x,int y)
{
    a[++size].dao=y;
    a[size].ne=last[x];
    last[x]=size;
}
inline void lingjiebiao3(int x,int y)
{
    c[++size3].dao=y;
    c[size3].ne=last3[x];
    last3[x]=size3;
}
inline int read()
{
    char c=getchar();
    int x=0,f=1;
    while(!isdigit(c)) {if(c=='-') f=-1;c=getchar();}
    while(isdigit(c)) {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*f;
}
inline void dfs1(int now)
{
    for(int i=last[now];i;i=a[i].ne)
    {
        if(book[a[i].dao]==0)
        {
            book[a[i].dao]=1;
            ji[i]=ji[i^1]=1;
            ans[a[i].dao]=ans[now]^1;
            dfs1(a[i].dao);
        }
    }
}
inline void dfs2(int now)
{
    for(int i=last3[now];i;i=c[i].ne)
    {
        if(book[c[i].dao]==book[now])
        {
            cout<<"B ";
            int hu=now;ans1=1;ans[ans1]=c[i].dao;
            while(hu!=c[i].dao)
            {
                ans1++;
                ans[ans1]=hu;
                hu=fa[hu];
            }
            cout<<ans1<<" ";
            for(int j=1;j<=ans1;j++) cout<<ans[j]<<" ";
            pan=1;
            return;
        }
        if(book[c[i].dao]==0x3f3f3f3f)
        {
            fa[c[i].dao]=now;
            book[c[i].dao]=book[now]^1;
            dfs2(c[i].dao);
            if(pan==1) return;
        }
    }
}
int main()
{
//    freopen("g.in","r",stdin);
//    freopen("g.out","w",stdout); 
    n=read();m=read();
    for(int i=1,x,y;i<=m;i++)
    {
        x=read();y=read();
        lingjiebiao(x,y);
        lingjiebiao(y,x);
    }book[1]=1;
    dfs1(1);
    for(int i=1;i<=n;i++)
        for(int j=last[i];j;j=a[j].ne)
            if(ji[j]==0) lingjiebiao3(i,a[j].dao);
    memset(book,0x3f3f3f3f,sizeof(book));
    for(int i=1;i<=n;i++)
    {
        if(book[i]==0x3f3f3f3f)
            book[i]=0,dfs2(i);
        if(pan==1) return 0;
    }
    cout<<"A ";
    for(int i=1;i<=n;i++)
        cout<<((ans[i]<<1)|book[i])+1<<" ";
    return 0;
}
View Code

t2 Sequence

Well before the 50 minutes out.

For 50 minutes after the first interrogation eight times, each time to ask the form {1, \ (10 ​​^ {49} \)}, so that we get the number 49 behind 8, as long as we determined the number of further this can be determined and the number 8 the number of 8-bit after another.

So twice the interrogation {0,1,0, \ (10 ​​^ {8} \), 0, \ (10 ​​^ {16}) \, ......}. These numbers can be derived 8.

To handwriting precision subtraction, the code amount, the code Mo was.

t3 walk

[Title] Italy

There are n number of locations, x-point action force, starting at 0, the restaurant location is 1-n, a restaurant can choose to eat a [i] some food, every step in after eating a k-point food need (k + 1 ) action, and can eat up to find a lot of points in the case of food can go back to the starting point.

For 30%

Virtually every local election if the price is i * a [i], the contribution is a [i]. 01 can be run directly backpack.

For 100%

Consider setting f [i] [j] shows that only come i - n a restaurant, eat a minimum cost j-th food needs. Transfer equation is simple \ (f [i] [j] = min (f [i + 1] [j], f [i + 1] [ja [i]] + a [i] * i) \), especially a, f [i] [a [i]], and from 2 * i + i * a [i] takes min.

The complexity of the analysis, because with food from j 0 i return to the required minimum price for i * j j so just to enumerate x / i can, complexity is O (nlogm).

code show as below:

#include <bits / STDC ++ H.>
 #define int Long Long
 the using  namespace STD;
 const  int N = 1E5 + . 5 ;
 int n-, K, A [N], F [ 2 ] [N * 10 ], L, R & lt, ANS ; // f [i] [j] j represents the lump eat food in these restaurants in the minimum cost spent. 
inline int Read () 
{ 
    char C = getchar ();
     int X = 0 , F = . 1 ;
     the while {(isdigit (C)!) IF (C == ' - ' ) F = - . 1 ; C = getchar () ;}
     the while(isdigit(c)) {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*f;
}
signed main()
{
    //freopen("w.in","r",stdin);
    //freopen("w.out","w",stdout);
    n=read();k=read();
    for(int i=1;i<=n;i++) a[i]=read();
    memset(f,0x3f3f3f3f,sizeof(f));
    for(int i=n;i>=1;i--)
    {
        
        for(int j=0;j<=k/i;j++)
        {
            f[i%2][j]=f[(i+1)%2][j];
            if(j>=a[i]) 
                f[i%2][j]=min(f[(i+1)%2][j],f[(i+1)%2][j-a[i]]+i*a[i]);
            if(f[i%2][j]<=k) ans=max(ans,j);
        }
        f[i%2][a[i]]=min(f[i%2][a[i]],i+i+a[i]*i);
        if(i+i+a[i]*i<=k) ans=max(ans,a[i]);
    }
    cout<<ans;
//    fclose(stdin);
//    fclose(stdout); 
    return 0;
}
/*
5 10
1 1 1 1 1
*/
View Code

Guess you like

Origin www.cnblogs.com/betablewaloot/p/12215990.html