A. Rudolph and Cut the Rope

思路

签到题,就是看有多少个钉子上系的绳子长度比钉子高度短

代码

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

using namespace std;

int t, n;

void solve()
{
cin >> n;
int ans = 0;
for (int i = 0; i < n; i ++ )
{
int a, b;
cin >> a >> b;
if (b < a) ans ++ ;
}
cout << ans << endl;
}

int main()
{
cin >> t;
while (t -- )
{
solve();
}
return 0;
}

B. Rudolph and Tic-Tac-Toe

题意

给你 3x3 网格的结果,问什么图案在行列或对角线一样,如果是“.”或者都没有就输出“DRAW”

思路

没想出啥好办法,暴力做了
(555代码被hack了我是大傻子…记得有三个“.”同排和三个其他字符同排时取其他字符!!

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>

using namespace std;

int t, n;
char a[4], b[4], c[4];

void solve()
{
for (int i = 0; i < 3; i ++ ) cin >> a[i];
for (int i = 0; i < 3; i ++ ) cin >> b[i];
for (int i = 0; i < 3; i ++ ) cin >> c[i];
// 判断列
for (int i = 0; i < 3; i ++ )
if (a[i] == b[i] && b[i] == c[i])
if (a[i] != '.')
{
cout << a[i] << endl;
return;
}
// 判断行
if (a[0] == a[1] && a[1] == a[2])
if (a[0] != '.')
{
cout << a[0] << endl;
return;
}
if (b[0] == b[1] && b[1] == b[2])
if (b[0] != '.')
{
cout << b[0] << endl;
return;
}
if (c[0] == c[1] && c[1] == c[2])
if (c[0] != '.')
{
cout << c[0] << endl;
return;
}
// 判断对角线
if (a[0] == b[1] && a[0] == c[2])
if (a[0] != '.')
{
cout << a[0] << endl;
return;
}
if (a[2] == b[1] && b[1] == c[0])
if (a[2] != '.')
{
cout << a[2] << endl;
return;
}
cout << "DRAW" << endl;
}

int main()
{
cin >> t;
while (t -- )
{
solve();
}
return 0;
}

C. Rudolf and the Another Competition

题意

给出算竞中的参赛人数、题数、时间和每一位选手做出每一题所需要的时间,求第一位选手最终排名

思路

算出每一位选手的过题数和罚时,得出第一位选手排名
注意罚时要记得开 long long / 痛

代码

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 200010;

int t, n, m, h;
int s[N], num[N];
LL pa[N]; // 罚时

void solve()
{
memset(num, 0, sizeof num);
memset(pa, 0, sizeof pa);
cin >> n >> m >> h;
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < m; j ++ ) cin >> s[j];
sort(s, s + m);
int sum = 0; // 选手用时
for (int j = 0; j < m; j ++ )
{
sum += s[j];
if (sum > h) break;
num[i] ++ ;
}
for (int j = 0; j < num[i]; j ++ ) pa[i] += (num[i] - j) * s[j];
}
int place = 1; // 目前排名,每出现一位比他成绩好的就将排名++
for (int i = 1; i < n; i ++ )
{
if (num[i] > num[0]) place ++ ;
else if (num[i] == num[0] && pa[i] < pa[0]) place ++ ;
}
cout << place << endl;
}

int main()
{
cin >> t;
while (t -- )
{
solve();
}
return 0;
}

D. Rudolph and Christmas Tree

题意

给定一个等腰三角形大小,给出三角形底边高度,问重叠之后总面积

思路

从下到上遍历每个三角形,后一个三角形覆盖了前一个就计算未被覆盖的面积,没覆盖就计算等腰三角形总面积,相加得出结果
(但这里本人犯了一个超级无敌蠢的错误导致wa了,浮点型除法乘1.0记得放在式子最开头哇!!

代码

#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int t, n, d, h;

void solve()
{
cin >> n >> d >> h;
double s = 0;
int temp;
cin >> temp;
for (int i = 1; i < n; i ++ )
{
int a;
cin >> a;
int x = a - temp;
if (x < h)
s += 1.0 * (2 * d - 1.0 * d * x / h) * x / 2;
else
s += 1.0 * d * h / 2;
temp = a;
}
s += 1.0 * d * h/ 2;
cout << fixed << setprecision(10) << s << '\n';
}

int main()
{
cin >> t;
while (t -- )
{
solve();
}
return 0;
}

E1. Rudolf and Snowflakes (simple version)

题意

雪花的构成:中间一个点,这个点可以向旁边发出 k (>=2)个点,发出的点又可以向外发出 k 个点,以此类推,问给定数目的点能不能构成一片雪花

思路

点的个数一定要是 1 + x + x^2^ + x^3^ + …
遍历所有的 x ,直到大于给定数目

代码

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

int t, n;

void solve()
{
cin >> n;
for (int i = 2; i <= n; i ++ )
{
LL sum = 1 + i + i * i;
LL temp = i * i;
if (sum > n) break;
while (sum < n)
{
temp *= i;
sum += temp;
}
if (sum == n)
{
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}

int main()
{
cin >> t;
while (t -- )
{
solve();
}
return 0;
}