# Link

https://www.acmicpc.net/problem/2456

 

2456번: 나는 학급회장이다

첫째 줄에는 반의 학생들의 수 N (3 ≤ N ≤ 1,000)이 주어진다. 다음 N개의 각 줄에는 각 학생이 제출한 회장후보 3명에 대한 선호 점수가 주어지는 데, 첫 번째 점수는 후보 1번에 대한 점수이고 두

www.acmicpc.net

 

 

# Code - C++

//
//  BOJ
//  ver.C++
//
//  Created by GGlifer
//
//  Open Source

#include <iostream>
#include <algorithm>
#include <tuple>

using namespace std;

#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))

// Set up : Definitions
struct Candidate { int no, score, cnt[3+1]; };

// Set up : Global Variables
/* None */

// Set up : Functions Declaration
bool operator != (const Candidate &u, const Candidate &v);
bool operator < (const Candidate &u, const Candidate &v);


int main()
{
    // Set up : I/O
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Set up : Input
    int N; cin >> N;
    Candidate C[3+1] = {{-1}, {1}, {2}, {3}};
    for (int i=0; i<N; i++) {
        int s1, s2, s3;
        cin >> s1 >> s2 >> s3;

        // Process
        C[1].cnt[s1]++; C[1].score += s1;
        C[2].cnt[s2]++; C[2].score += s2;
        C[3].cnt[s3]++; C[3].score += s3;
    }

    // Process
    sort(C+1, C+(3+1), greater<>());

    bool isUnique = (C[1] != C[2]);

    // Control : Output
    cout << ((isUnique) ? C[1].no : 0) << ' ' << C[1].score << endl;
}

// Helper Functions
bool operator != (const Candidate &u, const Candidate &v)
{
    auto ut = make_tuple(u.score, u.cnt[1], u.cnt[2], u.cnt[3]);
    auto vt = make_tuple(v.score, v.cnt[1], v.cnt[2], v.cnt[3]);
    return ut != vt;
}

bool operator > (const Candidate &u, const Candidate &v)
{
    auto ut = make_tuple(u.score, u.cnt[3], u.cnt[2], u.cnt[1]);
    auto vt = make_tuple(v.score, v.cnt[3], v.cnt[2], v.cnt[1]);
    return ut > vt;
}

 

 

지적, 조언, 첨언 모두 환영합니다!!!

# Link

https://www.acmicpc.net/problem/1526

 

1526번: 가장 큰 금민수

첫째 줄에 N이 주어진다. N은 4보다 크거나 같고 1,000,000보다 작거나 같은 자연수이다.

www.acmicpc.net

 

 

# Code - C++

//
//  BOJ
//  ver.C++
//
//  Created by GGlifer
//
//  Open Source

#include <iostream>
#include <queue>

using namespace std;

#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))

// Set up : Definitions
/* None */

// Set up : Global Variables
/* None */

// Set up : Functions Declaration
/* None */


int main()
{
    // Set up : I/O
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Set up : Input
    int N; cin >> N;

    // Process
    queue<int> Q;
    Q.push(0);

    int ans = -1;
    while (not(Q.empty())) {
        int c = Q.front(); Q.pop();

        if (c > N) continue;
        ans = c;

        Q.push(10*c + 4);
        Q.push(10*c + 7);
    }

    // Control : Output
    cout << ans << endl;
}

// Helper Functions
/* None */

 

 

지적, 조언, 첨언 모두 환영합니다!!!

# Link

https://www.acmicpc.net/problem/2473

 

2473번: 세 용액

첫째 줄에는 전체 용액의 수 N이 입력된다. N은 3 이상 5,000 이하의 정수이다. 둘째 줄에는 용액의 특성값을 나타내는 N개의 정수가 빈칸을 사이에 두고 주어진다. 이 수들은 모두 -1,000,000,000 이상

www.acmicpc.net

 

 

# Code - C++

//
//  BOJ
//  ver.C++
//
//  Created by GGlifer
//
//  Open Source

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))

// Set up : Definitions
/* None */

// Set up : Global Variables
/* None */

// Set up : Functions Declaration
/* None */


int main()
{
    // Set up : I/O
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Set up : Input
    int N; cin >> N;
    long V[N];
    for (int i=0; i<N; i++)
        cin >> V[i];

    // Process
    sort(V, V+N);

    vector<long> A = {V[0], V[1], V[2]};
    long ans_val = V[0] + V[1] + V[2];

    for (int i=0; i<N-2; i++) {
        int s = i+1, e = N-1;
        while (s < e) {
            long tmp_val = V[i] + V[s] + V[e];
            if (abs(ans_val) > abs(tmp_val)) {
                A = {V[i], V[s], V[e]};
                ans_val = tmp_val;

                if (ans_val == 0) {
                    goto end;
                }
            }

            (tmp_val > 0) ? e-- : s++;
        }
    } end:

    // Control : Output
    cout << A[0] << ' ' << A[1] << ' ' << A[2] << endl;
}

// Helper Functions
/* None */

 

 

지적, 조언, 첨언 모두 환영합니다!!!

+ Recent posts