Informatika gyűjtemény

Egy szinttel feljebb mb_selejtezo.cpp

2004050607080910

NézetNyomtat

mb_selejtezo.cpp (Vissza)
Az alábbi letöltési lehetőségek közül választhatsz: (segítség)
Karakterkódolás:
Sortörés:
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: us-ascii
Méret: 1 KB
#include <cstdio>
#include <iostream>
#include <fstream>

using namespace std;

void beolvas(char* fnin, char* fnout);

int p, c;
long long* s;

int main()
{
    beolvas("C-large-practice.in", "C-large-practice.out");
    return 0;
}

long long solve()
{
    bool cont=true;
    long long pmax, nmax;
    pmax=-1;
    while(cont)
    {
        nmax=0;
        for(int i=0; i<p; i++)
            nmax+=s[i];
        nmax=nmax/c;
        if(nmax==pmax)
        {
            cont=false;
            break;
        }
        
        for(int i=0; i<p; i++)
            if(s[i]>nmax)
                s[i]=nmax;
            
        pmax=nmax;
    }
    return pmax;
}

void beolvas(char* fnin, char* fnout)
{
    int n;
    ifstream reader(fnin);
    ofstream printer(fnout);
    reader >> n;
    for(int i=1; i<=n; i++)
    {
        reader >> p >> c;
        s=new __int64[p];
        for(int j=0; j<p; j++)
            reader >> s[j];
        cout << "Case #" << i << ": " << solve() << endl;
        printer << "Case #" << i << ": " << solve() << endl;
    }
    reader.close();
    printer.close();
    cin.get();
    /*int n;
    FILE* reader = fopen(fn, "r");
    fscanf(reader, "%d", &n);
    for(int i=1; i<=n; i++)
    {
        fscanf(reader, "%d %d", &p, &c);
        s=new int[p];
        for(int j=0; j<p; j++)
            fscanf(reader, "%llu", &s[j]);
        
        for(int j=0; j<p; j++)
            cout << s[j] << endl;
        solve();
    }
    
    fclose(reader);*/

}
(Vissza)