题解 P6188 【[NOI Online 入门组]文具订购(民间数据)】

Suuon_Kanderu

2020-03-08 09:05:22

Solution

来个暴力吧。我考场45分呜呜呜。 ``` #include<iostream> #include<cmath> #include<cstdio> #include<cstring> using namespace std; const int N = 0x7fffffff; int minn(int a,int b,int c) { int t = N; if(a < t)t = a; if(b < t)t = b; if(c < t)t = c; return t;//我竟然没写返回值 } signed main() { // freopen("order.in","r",stdin); // freopen("order.out","w",stdout); long long n,a,b,c,ma = 0,mb = 0,mc = 0; cin >> n; if(n%14 == 0){ cout << n/14 << " " << n/14 << " " << n/14 << endl; return 0; } for( a = 0; a <= n/7; a++){//枚举 for(int b = 0; b <= n/4; b++){//枚举 c = (-7*a-4*b+n)/3; //稍微一算就能算出来 if(c < 0)continue;//负数不可能的 if(7*a+4*b+3*c == n){ if(minn(a,b,c) > minn(ma,mb,mc)){ ma = a; mb = b; mc = c; continue; }//第二个条件 else if(minn(a,b,c) == minn(ma,mb,mc) && a + b + c > ma + mb +mc){//第三个条件 ma = a; mb = b; mc = c; } } } } if(ma == 0 && mb == 0 && mc == 0)cout << -1 << endl; else cout << ma << " " << mb << " " << mc << endl; // fclose(stdin); // fclose(stdout); return 0; } ``` 希望大家引以为戒,不要犯我这样的低级错误