結果
| 問題 |
No.1624 三角形の反射
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-07-24 19:15:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,491 bytes |
| コンパイル時間 | 699 ms |
| コンパイル使用メモリ | 95,128 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 09:54:56 |
| 合計ジャッジ時間 | 1,467 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1624.cc: No.1624 三角形の反射 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100;
/* typedef */
/* global variables */
char s[16];
/* subroutines */
template <typename T>
T gcd(T m, T n) { // m > 0, n > 0
if (m < n) swap(m, n);
while (n > 0) {
T r = m % n;
m = n;
n = r;
}
return m;
}
/* main */
int main() {
scanf("%s", s);
int gx = 1, gy = 0, pt = 0;
for (int i = 0; s[i]; i++) {
if (s[i] == '.') pt = 1;
else {
gy = gy * 10 + (s[i] - '0');
if (pt) gx *= 10;
}
}
int g = gcd(gx, gy);
gx /= g, gy /= g;
//printf("%d,%d\n", gx, gy);
int k = (gx - 1) + (gy - 1) + (gx + gy) / 2;
for (int z = 1; z < gy; z += 2) {
// y=x+z, y=(gy/gx)x
// x=0 -> (0,z),(0,0), x=gx -> (gx,gx+z),(gx,gy)
if (gx + z < gy) k++;
}
for (int z = -1; z > -gx; z -= 2) {
if (gx + z > gy) k++;
}
int p = (gx + gy) & 1;
// +C+C+C+
// B/C\B/C
// +B+B+B+
// B\C/B\C
// +C+C+C+
char c;
if (p == 0) c = 'A';
else if (gx > gy)
c = (gx & 1) ? 'B' : 'C';
else
c = (gy & 1) ? 'C' : 'B';
printf("%c %d\n", c, k);
return 0;
}
tnakao0123