線性容器

a b c d e f g

vector (動態陣列)

/*
 * f312. 1. 人力分配
 * C++
 * AC (2ms, 324KB)
*/
#include <bits/stdc++.h>
using namespace std;

int a1,b1,c1;
int a2,b2,c2;
int n;

bool cmp(int a,int b){
    return a>b;
}
  
int sum(int x1,int x2){
    int y1 = a1*x1*x1+b1*x1+c1;
    int y2 = a2*x2*x2+b2*x2+c2;
    return y1+y2;
}

int main(){
    cin >> a1 >> b1 >> c1;
    cin >> a2 >> b2 >> c2;
    cin >> n;
    vector<int> x(n,0);
    //
    for(int i=0;i<=n;i++){
        x.push_back(sum(i,n-i));
    }
    sort(x.begin(),x.end(),cmp);
    cout << x[0] << endl;
    return 0;
}

n個vector

/*
 * example
*/
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n = 5;
    vector<vector<int>> v(n, vector<int>(0));
    return 0;
}
/*
 0  1  2  3  4
 |  |  |  |  |
 |  |  |     |
 |     |     |
 |
*/

Last updated

Was this helpful?