으악~~~ 너무너무 어려웠다
너무~~ 너무ㅜㅜㅜ
이 문제를 이틀동안 고민했다는 게 사실입니까! (예 사실입니다.)
어느 부분에서 힘들었냐면 전체 경우의 수 세는 부분이 힘들었다.
1 1을 뽑았다고 하면 2 2 3 3 4 4 이렇게 남았을텐데
그럼 전체 경우의 수 셀 때 (2, 3) (2, 3) (2, 3) (2, 3) 이렇게 4 번 만들어지는 건지 아니면 그냥 (2, 3) 하나만 생각하는건지
그리고 (2, 3) (3, 2) 이런 것도 어떻게 생각해야 하는지
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
bool comp(const pair<int, int>& a, const pair<int, int>& b)
{
if (a.xx == a.yy)
{
if (b.xx == b.yy && a.xx < b.xx)
return true;
return false;
}
else
{
if (b.xx == b.yy)
return true;
if ((a.xx + a.yy) % 10 < (b.xx + b.yy) % 10)
return true;
return false;
}
}
int main()
{
ii n;
scanf("%d %d", &n.xx, &n.yy);
vector<ii> v;
for (int i = 1; i <= 10; i++)
{
for (int j = 1; j <= 10; j++)
{
v.emplace_back(i, j);
}
}
// sort(v.begin(), v.end(), sortbyfirst);
int cnt = 0;
int ans = 0;
for (int i = 0; i < v.size(); i++)
{
if ((n.xx == n.yy) && ((v[i].xx == n.xx) || (v[i].yy == n.yy)))
continue;
if ((n.xx != n.yy) && (v[i].xx == n.xx) && (v[i].yy == n.yy))
continue;
cnt++;
if (comp(v[i], n))
{
ans++;
printf("v[i] : %d %d n : %d %d\n", v[i].xx, v[i].yy, n.xx, n.yy);
}
}
printf("%d %d\n", ans, cnt);
printf("%.5lf\n", (double)ans / cnt);
return 0;
}
위의 그런 생각들때문에 코드 어디서 문제가 있었던듯
암튼.. 고민 해결을 하자면 (2, 3) (2, 3) (2, 3) (2, 3) 4 개를 만드는 게 맞고 (2, 3) == (3, 2)가 같은 걸로 생각해야 한다 (그야 뽑으면 순서가 없는 거랑 마찬가지니깐)
그래서 아래처럼 문제 해결~~
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
bool comp(const pair<int, int>& a, const pair<int, int>& b)
{
if (a.xx == a.yy)
{
if (b.xx == b.yy && a.xx < b.xx)
return true;
return false;
}
else
{
if (b.xx == b.yy)
return true;
if ((a.xx + a.yy) % 10 < (b.xx + b.yy) % 10)
return true;
return false;
}
}
int main()
{
ii n;
scanf("%d %d", &n.xx, &n.yy);
vector<int> card;
for (int i = 0; i < 2; i++)
{
for (int j = 1; j <= 10; j++)
{
card.emplace_back(j);
}
}
card.erase(find(card.begin(), card.end(), n.xx));
card.erase(find(card.begin(), card.end(), n.yy));
vector<ii> v;
for (int i = 0; i < card.size(); i++)
{
for (int j = i + 1; j < card.size(); j++)
{
v.emplace_back(card[i], card[j]);
}
}
int ans = 0;
for (int i = 0; i < v.size(); i++)
{
if (comp(v[i], n))
ans++;
}
printf("%.3lf\n", (double)ans / v.size());
return 0;
}
for (int i = 0; i < card.size() - 1; i++)
{
for (int j = i + 1; j < card.size(); j++)
{
v.emplace_back(card[i], card[j]);
}
}
처음에 코드를 이렇게 짰는데 문제점이 있었다!
card.size()가 unsigned int라 -1 뺄 때 이상한 값 들어갈 수 있음
이 코드에서는 card - 1 안 해도 문제 없어서 저기 붙은 -1은 때줬다
'백준' 카테고리의 다른 글
1411 비슷한 단어 (0) | 2020.09.05 |
---|---|
3036 링 (0) | 2020.09.03 |
1064 평행사변형 (0) | 2020.08.31 |
1493 박스 채우기 (0) | 2020.08.30 |
10713 기차 여행 (0) | 2020.08.28 |