G题
水题
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
struct meal {
int n;
string s[60];
}a[100];
int main() {
int t;
int max = 0, index = 0;
cin >> t;
for (int i = 0; i < t; i ++) {
int n;
cin >> n;
if (n > max)
max = n, index = i;
a[i].n = n;
for (int j = 0; j < n; j ++) {
cin >> a[i].s[j];
}
}
cout << max << endl;
for (int j = 0; j < max; j ++) {
cout <<a[index].s[j] << endl;
}
}
I题
I题是给出角、边、内部的块,看能不能恰好拼成一个拼图。自己在写这个题时是将内部的块因数分解,看是否存在一种情况使因数和的两倍等于边块的和,有就是符合题意。但自己这样做产生了一个问题就是当内部块为0的情况自己没有考虑到,所以自己wa了四次。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll cnt = 0;
struct num {
ll a, b;
}a[100000010];
void get_d(ll x) {
for (ll i = 1; i <= x / i; i ++ )
if (x % i == 0)
{
a[cnt].a = i;
a[cnt].b = x / i;
cnt ++;
}
}
int main() {
ll jiao, bian, nei;
cin >> jiao >> bian >> nei;
if (jiao != 4 || bian % 2 != 0) {
cout << "impossible" << endl;
return 0;
}
ll chang = 0, kuan = 0;
get_d(nei);
for (ll i = 0; i < cnt; i ++) {
chang = max(a[i].a, a[i].b);
kuan = min(a[i].a, a[i].b);
if (chang * 2 + kuan * 2 == bian) {
cout << chang + 2 << ' ' << kuan + 2 << endl;
return 0;
}
}
if (nei == 0 && bian % 2 == 0){
cout << bian / 2 + 2 << ' ' << '2' << endl;
return 0;
}
cout << "impossible" << endl;
}
C题
这个题自己在做的时候对0没有处理好,看到样例中最后出现0,就在计数的时候把0也记上了,最后导致自己在判断“ambiguous”的时候总是出错;这个题输出过题数时从0开始输出比较难,第一次做的时候我是从0输出,先把结果存在数组里再倒着输出,后来发现没有必要,直接倒着输出就行了。
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e6;
int a[N];
int main() {
int n, m;
cin >> n >> m;
int cnt = 1;
for (int i = 0; i < n; i ++) {
scanf("%d", &a[i]);
if (i >= 1 && a[i] < a[i - 1] && a[i] != 0) {
cnt ++;
}
}
if (cnt != m && a[0] != 0) {
// cout << cnt;
puts("ambiguous");
return 0;
}
for (int i = 0; i < n; i ++) {
if (a[0] == 0) {
m = 0;
}
if (i == 0)
cout << m << endl;
else {
if (a[i] < a[i - 1])
printf("%d\n", --m);
else
printf("%d\n", m);
}
}
}