結果
| 問題 |
No.133 カードゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-18 11:04:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 120 ms / 5,000 ms |
| コード長 | 937 bytes |
| コンパイル時間 | 608 ms |
| コンパイル使用メモリ | 49,152 KB |
| 最終ジャッジ日時 | 2025-01-08 19:57:18 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:29:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | for(int i=0; i<n; ++i) { scanf("%d", &a[i]); }
| ~~~~~^~~~~~~~~~~~~
main.cpp:30:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | for(int i=0; i<n; ++i) { scanf("%d", &b[i]); }
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <vector>
using namespace std;
using u32 = uint32_t;
u32 uy = u32(time(NULL));
u32 xorshift32() {
uy ^= uy << 14;
uy ^= uy >> 13;
uy ^= uy << 15;
return uy;
}
template<class T>
void shuffle(vector<T> *v) {
size_t n = v->size();
for(size_t i=n-1; i>=1; --i) {
size_t k = xorshift32() % (i + 1);
if(k == i) { continue; }
swap(v->at(k), v->at(i));
}
}
int main(void) {
int n; scanf("%d", &n);
vector<int> a(n), b(n);
for(int i=0; i<n; ++i) { scanf("%d", &a[i]); }
for(int i=0; i<n; ++i) { scanf("%d", &b[i]); }
constexpr int N = 1000000;
int cnt = 0;
for(int loop=0; loop<N; ++loop) {
shuffle(&a);
shuffle(&b);
int ptr = 0;
for(int i=0; i<n; ++i) {
if(a[i] > b[i]) { ++ptr; }
if(a[i] < b[i]) { --ptr; }
}
if(ptr > 0) { ++cnt; }
}
double res = cnt * 1. / N;
printf("%lf\n", res);
return 0;
}