zoukankan      html  css  js  c++  java
  • 暴利链表 钟

    问题 B: 钟

    时间限制: 4 Sec  内存限制: 512 MB

    题目描述

    输入

    3 6

    0 -1 1

    1 0 -1

    -1 1 0

    1 2 3 1 2 3

    输出

    5

    提示

           我怀疑这道题出题人是来送钟的。。。然而出题人智商又被虐了。。暴力跑链表就能过。。。

           有一种优化,可以算出这个钟什么时候挂掉。。就不用挨个枚举时间了。

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int read()
    {
    	int sum=0,f=1;char x=getchar();
    	while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();}
    	while(x>='0'&&x<='9'){sum=(sum<<1)+(sum<<3)+x-'0';x=getchar();}
    	return sum*f;
    }
    int c,n,a[105][105],col[1000005],hh[105],sum[105];
    int nex[1000005],fro[1000005],v[1000005];
    int main()
    {
    	freopen("clock.in","r",stdin);
    	freopen("clock.out","w",stdout);
    	c=read();n=read();
    	for(int i=1;i<=c;i++)
    	   for(int j=1;j<=c;j++)
    	       a[i][j]=read();   
    	for(int i=1;i<=n;i++)
    	  nex[i]=i+1,fro[i]=i-1,col[i]=read(),v[i]=1;
    	nex[0]=1;nex[n]=0;
    	while(1)
    	{
    		int p=0,k=col[nex[0]];
    		for(int i=nex[0];i;i=nex[i])
    		    if(col[i]!=k){p=1;break;}
    		if(!p)break;
    		for(int i=nex[0];i;i=nex[i])
    		    v[i]+=a[col[i]][col[fro[i]]]+a[col[i]][col[nex[i]]];
    		for(int i=nex[0];i;i=nex[i])
    			if(v[i]<=0)fro[nex[i]]=fro[i],nex[fro[i]]=nex[i];
    	}
    	printf("%d
    ",col[nex[0]]);
    }
       

  • 相关阅读:
    POJ2524+并查集
    POJ3697+BFS+hash存边
    POJ1151+线段树+扫描线
    POJ2528+线段树
    ubuntu 和 win7 远程登陆 + vnc登陆
    POJ3690+位运算
    POJ3283+字典树
    POJ3282+模拟
    POJ2349+prim
    2016.6.13
  • 原文地址:https://www.cnblogs.com/QTY2001/p/7632716.html
Copyright © 2011-2022 走看看