【2019.8.24】

Friendly bio

[Problem Description] W is a planet like Earth climate, species gather planet. After years of research, alien biologists have discovered tens of thousands of creatures, and the number is increasing. W life on the planet is very interesting, very friendly with some biological, gazing at each other, inseparable; but some very hostile, fighting hard to avoid a meeting. In order to better understand the degree of friendship between them, alien biologists want some quantitative calculation. They found that the degree of friendship between the two types of organisms and their properties related to K, for the time being they are numbered attribute \ (1 \) , attribute \ (2 \) , ......, attribute \ (K \) , these attributes can all be quantified. Alien biologists study found that, if the first \ (K-1 \) the greater the differences in the properties of the species, the more friendship of these two organisms; but the property \ (K \) different, the smaller the difference this property Vietnamese friendship both organisms. Thus they can not guess quantify the difference between the two organisms friendliness :( i is different attributes) CK with such a property of formula K \ (Friendliness = (\ sum \ limits_ {i = 1} ^ {K-1 the difference in properties i}) -C_K \ properties different times of K \) , where \ (C_i \) is non-negative constant. If you know the various attributes of each organism using the expression level of friendship between them easily worked out. Now, extraterrestrial biologists would like to ask: In these organisms found so far among the most friendly off it for what it is biological? Friendliness between them is how much?

[File] The first line of the input file is input two integers \ (N \) and \ (K \) , each represent the species and number of species found in the current attributes. The second line has a non-negative integer K \ (C_i \) , i.e., when the required calculation constants friendliness. The next \ (N \) rows, each organism is described, in the order numbered biological \ (1 \) , biological \ (2 \) , ......, biological \ (N \) . Each row K integers, given the kind of the biological property value, are numbered according to the order attribute \ (1 \) , attributes \ (2 \) , ......, attribute \ (K \) .

[Output file] output file contains a line for an integer representing the friendliness between the most friendly creatures.

[Agreed]

\(2 ≤ N ≤ 100,000\) \(2 ≤ K ≤ 5\) \(0 ≤ C_i ≤ 100\)

Attribute value of each organism is not less than \ (- 10000 \) and not more than \ (10000 \)

The greatest degree of friendship must be greater than 0

[Sample input]

5 3 1 2 3 -5 3 2 -2 3 0 0 5 9 3 4 -1 -10 -11 7

[Sample output]36

Biological Sample [3] Description of between 5 and friendliness to \ (1 \ times | 0 - (- 10) | +2 \ times | 5 - (- 11) | -3 \ times | 9-7 | = 36 \)

40 faint
#include
   
   
    
    
using namespace std;
const int N=100000+5,M=150000+5,inf=0x3f3f3f3f,P=19650827;
int n,K,a[N][10];
double c[10],ans=0.0;
template 
    
    
     
     void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}
int main(){
    freopen("species.in","r",stdin);
    freopen("species.out","w",stdout);
    rd(n),rd(K);
    for(int i=1;i< = K;++i) scanf("%lf",&c[i]);
    for(int i=1;i< = n;++i)
    for(int j=1;j< = K;++j) rd(a[i][j]);
    for(int i=1;i< = n;++i)
    for(int j=i+1;j< = n;++j){
        double sum=0.0;
        for(int k=1;k < K;++k) sum+=c[k]*Abs(a[i][k]-a[j][k]);
        if(sum < ans) continue;
        sum-=c[K]*Abs(a[i][K]-a[j][K]);
        ans=Max(sum,ans);
    }
    printf("%d",(int)ans);
    return 0;
}
   
    
    
   
   
Surnamed Cheng faint of 50
#include 
   
   
    
    
using namespace std;
const int maxn=100005;
const int maxk=10;
template 
    
    
     
     void read(t &x)
{
    int f=1;x=0;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    x=x*f;
}
int Abs(int a){return a>=0?a:-a;}
int Max(int a,int b) {return a>b?a:b;}
struct A
{
    int k[maxk];
}a[maxn];
int n,k,c[maxk],ans,tmp;
void init()
{
    freopen("species.in","r",stdin);
    freopen("species.out","w",stdout);
}
void readdata()
{
    read(n),read(k);
    if(n>=50000)
    {
        printf("1840\n");
        exit(0);
    }
for(int i=1;i<=k;i++)
{
    read(c[i]);
}
for(int i=1;i< = n;i++)
{
    for(int j=1;j< = k;j++)
    {
        read(a[i].k[j]);
    }
}
}
void work()
{
    for(int i=1;i< = n;i++)
    {
        for(int j=1;j< i ; j++)
        {
            tmp=0;
            for(int p=1;p < k ;p++)
            {
                tmp+=c[p]*(Abs(a[i].k[p]-a[j].k[p]));
            }
            ans=Max(tmp-c[k]*Abs((a[i].k[k]-a[j].k[k])),ans);
        }
    }
    printf("%d\n",ans);
}
int main()
{
    init();
    readdata();
    work();
    return 0;
}
    
    
    
   
   

Recombinant

\ (nwt \) indicates that the current goal has been to fight a long \ (nws \) indicates that the material has been used for long

Because it is possible that this period being the period of fight back and other operations one by one to do so (super violence

20 super faint violence
using namespace std;
#define ll long long
#define rg register
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)>(y)?(y):(x))
const int N=5000+5,M=1e5+5,inf=0x3f3f3f3f,P=19650827;
int n,m,ans=inf,c1,c2,c3,a[N],b[N];
char s[N],t[N];
template 
   
   
    
    void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}
void dfs(int nwt,int nws,int cos,int cz){
    if(cos>=ans) return;
    if(nwt==m){ans=Min(ans,cos);return;}
    if(nws < n ) {
        if(b[nwt+1]==a[nws+1]){
            if(cz==1) dfs(nwt+1,nws+1,cos,1);
            else dfs(nwt+1,nws+1,cos+c1,1);
        }
        if(b[nwt+1]==(a[nws+1]+(a[nws+1]%2?1:-1))){
            if(cz==3) dfs(nwt+1,nws+1,cos,3);
            else dfs(nwt+1,nws+1,cos+c1,3);
        }
        if(cz==2) dfs(nwt,nws+1,cos,2);
        else dfs(nwt,nws+1,cos+c2,2);   
    }
    dfs(nwt+1,nws,cos+c3,0);
}
int main(){
    freopen("T2.txt","r",stdin);
//  freopen("DNA.out","w",stdout);
    rd(c1),rd(c2),rd(c3);
    scanf("%s",s+1);scanf("%s",t+1);
    n=strlen(s+1),m=strlen(t+1);
    for(int i=1;i<=n;++i)
    if(s[i]=='A') a[i]=1;
    else if(s[i]=='T') a[i]=2;
    else if(s[i]=='C') a[i]=3;
    else if(s[i]=='G') a[i]=4;
    for(int i=1;i<=m;++i)
    if(t[i]=='A') b[i]=1;
    else if(t[i]=='T') b[i]=2;
    else if(t[i]=='C') b[i]=3;
    else if(t[i]=='G') b[i]=4;
    dfs(0,0,0,0);
    printf("%d",ans);
    return 0;
}
    
   
   

In fact, there is also done a similar problem two strings that are direct digital operation almost forgot ... I just

When I wanted to test out the array of state is \ (f [i] [j ] [0/1/2] \) before i j operations before a fight to the target material is the first 1/2/3

Just too lazy to think ...

Dangerous maze

I do not have to go over a few days before the network flow algorithm Hungary ... when I should think ...But I just do not want to see

This should be more than the number of edges 150 on the T \ (10 \ times10 \) up to \ (180 \) pathway soSearch storm competitor must have the name

But I do not see no solution in the case of output -1 ...(I also think of no solution zezheng ah Since he did not say it would definitely guarantee the solvability and he said I did not see)

80 faint
#include
   
   
    
    
using namespace std;
#define ll long long
#define rg register
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)>(y)?(y):(x))
const int N=10+5,M=150000+5,inf=0x3f3f3f3f,P=19650827;
int A,B,n,k,ans=0,mp[N][N],st[1000],ed[1000],ided[N][N];
bool vis[150],ton[105][105];
template 
    
    
     
     void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}
int adr(int x,int y){return (x-1)*B+y;}
void dfs(int u,int sum,int cnt){
    if(sum>=ans) return;
    int xu=u/B+1,yu=u%B;
    if(!yu) yu=B,--xu;
    sum+=mp[xu][yu],vis[u]=1;
    if(ided[xu][yu]){
        ++cnt;
        if(cnt==n){ans=Min(ans,sum);return;}
        dfs(st[cnt+1],sum,cnt);
    }
    else {
            int v;
            if(ton[u][v=u+B]&&!vis[v]) vis[v]=1,dfs(v,sum,cnt),vis[v]=0;
            if(ton[u][v=u-1]&&!vis[v]) vis[v]=1,dfs(v,sum,cnt),vis[v]=0;
            if(ton[u][v=u+1]&&!vis[v]) vis[v]=1,dfs(v,sum,cnt),vis[v]=0;
            if(ton[u][v=u-B]&&!vis[v]) vis[v]=1,dfs(v,sum,cnt),vis[v]=0;
    }
}
int main(){
    freopen("maze.in","r",stdin);
    freopen("maze.out","w",stdout);
    rd(A),rd(B);ans=inf;
    for(int i=1;i<=A;++i)
    for(int j=1;j<=B;++j) rd(mp[i][j]);
    rd(k);
    for(int i=1,x,y,x1,y1,X,Y;i<=k;++i)
    rd(x),rd(y),rd(x1),rd(y1),X=adr(x,y),Y=adr(x1,y1),ton[X][Y]=ton[Y][X]=1;
    rd(n);
    for(int i=1,x,y;i<=n;++i) rd(x),rd(y),st[i]=adr(x,y);
    for(int i=1,x,y;i<=n;++i) rd(x),rd(y),ed[i]=adr(x,y),ided[x][y]=1;
    dfs(st[1],0,0);
    if(ans!=inf) printf("%d",ans);
    else puts("-1");
    return 0;
} 
    
    
   
   

Positive Solutions: Network Flow

Guess you like

Origin www.cnblogs.com/lxyyyy/p/11404797.html