20分求助

P6188 [NOI Online #1 入门组] 文具订购

SIXIANG32 @ 2020-03-08 11:53:44

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n=1000000,z;
    cin>>n;
    for(int p=n/3;p>=1;p--)//一共可以买多少笔记本 
        for(int i=n/4;i>=1;i--)//一共可以买多少笔 
            {
                z=(n-(p*3)-(i*4))/7;
                if(z*7+p*3+i*4==n&&z>0&&i>0&&p>0)
                {
                    cout<<z<<' '<<i<<' '<<p<<endl;
                    return 0;
                }
            }
    cout<<-1;
    return 0;
}

20分求助QWQ


by _JEB_ @ 2020-03-08 12:01:35

大佬

请你看清题目

@SIXIANG


by _JEB_ @ 2020-03-08 12:01:52

@SIXIANG


by SIXIANG32 @ 2020-03-08 12:02:41

@Charlie___j 嗯???


by _JEB_ @ 2020-03-08 12:03:16

2,3两个条件你都没判断


by _JEB_ @ 2020-03-08 12:04:50

#include<bits/stdc++.h>
using namespace std;
int min1[1000001],s[10000001],a[1000001],b[1000001],c[1000001];
int main(){
    freopen("order.in","r",stdin);freopen("order.out","w",stdout);
    min1[1]=999999999;
    int n,acm=1,k1,k2,k,csp=1,max=-999,u=0,max2=-999,p=0;
    int x;
    cin>>n;
    if(n==1){
        cout<<-1;return 0;
    }
    if(n==2){
        cout<<-1;return 0;
    }
    if(n==3){
        cout<<"0 0 1";return 0;
    }
    if(n==4){
        cout<<"0 1 0";return 0;
    }
    if(n==5){
        cout<<-1;return 0;
    }
    if(n==6){
        cout<<-1;return 0;
    }
    if(n==7){
        cout<<"0 1 1";return 0;
    }
    if(n==8){
        cout<<-1;return 0;
    }
    if(n==9){
        cout<<"0 0 3";return 0;
    }
    if(n==10){
        cout<<"0 1 2";return 0;
    }
    if(n==11){
        cout<<"0 2 1";return 0;
    }
    if(n==12){
        cout<<"0 0 4";return 0;
    }
    if(n==13){
        cout<<"1 0 2";return 0;
    }
    if(n==14){
        cout<<"1 1 1";return 0;
    }
    for(int i=1;i<=n/7;i++){
        for(int j=1;j<=n/4;j++){
            x=n-i*7-j*4;
            if(x%3==0&&x>2){
                k=x/3;
                csp++;
                k1=min(i,j);
                k1=min(k1,k);
                min1[csp]=min(min1[csp-1],k1);
                s[acm]=i+j+k;
                //cout<<i<<" "<<j<<" "<<k<<" "<<min1[csp]<<" "<<s[acm]<<endl;
                acm++;
                u++;
                a[acm]=i;
                b[acm]=j;
                c[acm]=k;
            }   
        }
    }
    sort(min1+2,min1+csp,greater<int>());
    sort(s+1,s+acm,greater<int>());
    for(int i=2;i<=acm;i++){
        if(min1[i]>max){
            max=min1[i];
        }
    }
    for(int i=1;i<=acm-1;i++){
        if(s[i]>max2){
            max2=s[i];
        }
    }
    for(int i=2;i<=acm;i++){
        if(max==min1[i]){p++;
            if(max2==s[p]){
                cout<<a[i]<<" "<<b[i]<<" "<<c[i];return 0;
            }
        }
    }
    cout<<-1;

}
//min1:2-acm;
//s:   1-acm-1
/*
1 3 5  9  1
1 6 1  8  1
2 2 4  8  1
3 1 3  7  1
*/

我的代码 仅供参考


by _JEB_ @ 2020-03-08 12:05:19

前面不用看(保证基础分30分)

@SIXIANG


by _JEB_ @ 2020-03-08 12:05:56

代码写的有点复杂


by _JEB_ @ 2020-03-08 12:06:31

这题不知道是不是我想复杂了

@SIXIANG


by _JEB_ @ 2020-03-08 12:06:44

在吗


by SIXIANG32 @ 2020-03-08 12:07:28

@Charlie___j zai


| 下一页