zoukankan      html  css  js  c++  java
  • P2421 [NOI2002]荒岛野人 扩展欧几里得 枚举

    Code:

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    int N;
    struct Node{
    	ll C,P,L;
    }nodes[20];
    ll abss(ll a){return a<0?-a:a;}
    ll exgcd(ll a,ll b,ll &x,ll &y){
    	if(b==0){x=1,y=0;return a;}
    	ll ans=exgcd(b,a%b,x,y);
    	ll tmp=x;
    	x=y,y=tmp-a/b*y;
    	return ans;
    }
    int check(int M){
    	for(int i=1;i<N;++i)
    		for(int j=i+1;j<=N;++j)
    		{
    			ll a=nodes[i].P-nodes[j].P,b=M,c=nodes[j].C-nodes[i].C;
    			ll x,y,mod,ans;
    			ans=exgcd(a,b,x,y);
    			if(c%ans!=0)continue;
    			x*=(c/ans);
    			mod=abss(b/ans);
    			x=((x%mod)+mod)%mod;
    			if(x<=nodes[i].L&&x<=nodes[j].L)return 0;
    		}
    	return 1;
    }
    int main(){
    	//freopen("in.txt","r",stdin);
    	ll u=0;
    	scanf("%d",&N);
    	for(int i=1;i<=N;++i){
    		scanf("%lld%lld%lld",&nodes[i].C,&nodes[i].P,&nodes[i].L);
    		u=max(u,nodes[i].C);
    	}
    	int ans=u;
    	for(;;++ans)if(check(ans))break;
    	printf("%d",ans);
    	return 0;
    }
    

      

  • 相关阅读:
    day10
    day 9
    day 8
    flex布局
    简单的todolist的demo
    JS中数组与对象的遍历方法实例小结
    css中animation和@keyframes 动画
    form表单相关
    Restful API接口规范
    什么是接口文档,如何写接口,有什么规范?
  • 原文地址:https://www.cnblogs.com/guangheli/p/9847089.html
Copyright © 2011-2022 走看看