zoukankan      html  css  js  c++  java
  • cf1244C

    题意简述:给出n,p,w,d,找到满足下面要求的一组解,x,y,z>=0

    扩展欧几里得会爆longlong,但是注意观察可以发现,如果有解y<w一定有解,因为d*w可以让x去凑

    #include<bits/stdc++.h>
    #define forn(i, n) for (int i = 0 ; i < int(n) ; i++)
    #define fore(i, s, t) for (int i = s ; i < (int)t ; i++)
    #define fi first
    #define se second
    #define all(x) x.begin(),x.end()
    #define pf2(x,y) printf("%d %d
    ",x,y)
    #define pf(x) printf("%d
    ",x)
    #define each(x) for(auto it:x)  cout<<it<<endl;
    #define pii pair<int,int>
    using namespace std;
    typedef long long ll;
    const int maxn=2e6+5;
    const int maxm=2e5+5;
    const int inf=1e9;
    ll n,p,w,d;
    
    int main(){
    	cin>>n>>p>>w>>d;
    	for(ll i=0;i<w;i++){
    		ll res=p-i*d;
    		if(res>=0 && res%w==0 && i+res/w<=n){
    			cout<<res/w<<' '<<i<<' '<<n-i-res/w<<endl;
    			return 0;
    		}
    	}
    	puts("-1");
    	
    }
    

      

  • 相关阅读:
    Excel Add-in
    并发控制MsSql
    Kaggle实战分类问题2
    NuGet
    Pomelo分布式游戏服务器框架
    Ambari
    oracle 多行转多列查询
    Oauth2.0 用Spring-security-oauth2
    bug排查小结
    Linux之lsof命令
  • 原文地址:https://www.cnblogs.com/033000-/p/12380353.html
Copyright © 2011-2022 走看看