题目链接:A. Okabe and Future Gadget Laboratory
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int maxn = 53;
int m[maxn][maxn];
int n;
bool work(int x, int y) {
vector<int> A; ///row
vector<int> B; ///column
for(int i = 1; i <= n; i++) {
if(i != y) {
A.push_back(m[x][i]);
}
}
for(int i = 1; i <= n; i++) {
if(i != x) {
B.push_back(m[i][y]);
}
}
for(int i = 0; i < n-1; i++) {
for(int j = 0; j < n-1; j++) {
if(A[i] + B[j] == m[x][y]) {
return false;
}
}
}
return true;
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
scanf("%d", &m[i][j]);
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(m[i][j] != 1) {
bool ok = work(i, j);
if(ok) {
printf("No\n");
return 0;
}
}
}
}
printf("Yes\n");
return 0;
}
题目链接:B. Okabe and Banana Trees
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int INF = 0x7fffffff;
long long m, b;
long long getX(long long y) {
return m*(b-y);
}
long long getY(long long x) {
double res = -((x*1.0)/m) + b;
return (long long)res;
}
int main()
{
cin >> m >> b;
long long maxValue = -INF;
long long result;
long long i, j;
for(j = b; j >= 0; j--) {
i = getX(j);
result = (j*(1+j)*(1+i))/2 + (i*(i+1)*(1+j))/2;
maxValue = max(maxValue, result);
}
long long Size = m*b;
for(i = 0; i <= Size; i++) {
j = getY(i);
result = (j*(1+j)*(1+i))/2 + (i*(i+1)*(1+j))/2;
maxValue = max(maxValue, result);
}
cout << maxValue << endl;
return 0;
}
题目链接:C. Okabe and Boxes
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
vector<int> V;
bool cmp(int x, int y) {
if(x > y) return true;
return false;
}
int main()
{
char str[10];
int x;
scanf("%d", &n);
int Size = 2*n;
int lastest = 0;
int index;
int cnt = 0;
for(int i = 1; i <= Size; i++ ) {
scanf("%s", str);
if(str[0] == 'a') {
scanf("%d", &x);
V.push_back(x);
} else {
index = (int)V.size()-1;
if(V[index] == lastest+1) {
lastest = V[index];
V.pop_back();
} else {
cnt++;
sort(V.begin(), V.end(), cmp);
index = V.size()-1;
lastest = V[index];
V.pop_back();
}
}
}
printf("%d\n", cnt);
return 0;
}
题目大意:A. Mister B and Book Reading
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int c, v0, v1, a, l;
int total = 0;
int main() {
scanf("%d%d%d%d%d", &c, &v0, &v1, &a, &l);
c = c - v0;
total++;
if(c <= 0) {
printf("1\n");
return 0;
}
int v = v0;
while(c > 0) {
v += a;
if(v >= v1) v = v1;
c += l;
c -= v;
total++;
}
printf("%d\n", total);
}