t1-apple 小苹果
#include <iostream>
using namespace std;
int m(double x) { return (int)x == x ? x : x + 1; }
int n, ans1, ans2 = -1;
int main() {
cin >> n;
for (int i = 1;; i++) {
if (n == 0) break;
if (ans2 == -1 && n % 3 == 1) ans2 = i;
n -= m(n / 3.0);
ans1++;
}
cout << ans1 << ' ' << ans2 << endl;
return 0;
}
t2-road 公路
#include <iostream>
#define N 100010
#define ll long long
using namespace std;
int n;
ll d, v[N], p[N], ans;
int main() {
cin >> n >> d;
for (int i = 1; i < n; i++) cin >> v[i];
for (int i = 1; i <= n; i++) cin >> p[i];
int now = 1, nxt = 2;
ll tank = 0;
while (now < n) {
ll dis = v[now];
while (nxt < n && p[nxt] >= p[now]) dis += v[nxt++];
int cnt = 0;
while (tank + cnt * d < dis) cnt++;
ans += p[now] * cnt;
tank += cnt * d - dis;
now = nxt++;
}
cout << ans << endl;
return 0;
}
t3-uqe 一元一次方程
#include <bits/stdc++.h>
using namespace std;
int a, b, c, T, M, fz, fm;
int gcd(int x, int y) {
if (x % y == 0) return y;
return gcd(y, x % y);
}
int main() {
scanf("%d%d", &T, &M);
while (T--) {
scanf("%d%d%d", &a, &b, &c);
int gen = b * b - 4 * a * c;
if (gen < 0) {
printf("NO\n");
} else if (sqrt(gen) == int(sqrt(gen))) {
fz = -b + sqrt(gen) * (a > 0 ? 1 : -1);
fm = 2 * a;
if (fz % fm == 0) {
printf("%d\n", fz / fm);
} else {
if (fz * fm < 0) printf("-");
int k = gcd(abs(fz), abs(fm));
printf("%d/%d\n", abs(fz) / k, abs(fm) / k);
}
} else {
if (b != 0) {
fz = -b;
fm = 2 * a;
if (fz % fm == 0) {
printf("%d+", fz / fm);
} else {
if (fz * fm < 0) printf("-");
int k = gcd(abs(fz), abs(fm));
printf("%d/%d+", abs(fz) / k, abs(fm) / k);
}
}
int ma = 1;
for (int i = 2; i * i <= gen; i++) {
while (gen % (i * i) == 0) {
ma *= i;
gen /= i * i;
}
}
fz = ma;
fm = abs(2 * a);
if (fz % fm == 0) {
if (fz != fm) printf("%d*", fz / fm);
printf("sqrt(%d)\n", gen);
} else {
int k = gcd(abs(fz), abs(fm));
if (fz / k != 1) printf("%d*", fz / k);
printf("sqrt(%d)/%d\n", gen, fm / k);
}
}
}
return 0;
}
t4-bus 旅游巴士
#include <bits/stdc++.h>
using namespace std;
int a, b, c, T, M, fz, fm;
int gcd(int x, int y) {
if (x % y == 0) return y;
return gcd(y, x % y);
}
int main() {
scanf("%d%d", &T, &M);
while (T--) {
scanf("%d%d%d", &a, &b, &c);
int gen = b * b - 4 * a * c;
if (gen < 0) {
printf("NO\n");
} else if (sqrt(gen) == int(sqrt(gen))) {
fz = -b + sqrt(gen) * (a > 0 ? 1 : -1);
fm = 2 * a;
if (fz % fm == 0) {
printf("%d\n", fz / fm);
} else {
if (fz * fm < 0) printf("-");
int k = gcd(abs(fz), abs(fm));
printf("%d/%d\n", abs(fz) / k, abs(fm) / k);
}
} else {
if (b != 0) {
fz = -b;
fm = 2 * a;
if (fz % fm == 0) {
printf("%d+", fz / fm);
} else {
if (fz * fm < 0) printf("-");
int k = gcd(abs(fz), abs(fm));
printf("%d/%d+", abs(fz) / k, abs(fm) / k);
}
}
int ma = 1;
for (int i = 2; i * i <= gen; i++) {
while (gen % (i * i) == 0) {
ma *= i;
gen /= i * i;
}
}
fz = ma;
fm = abs(2 * a);
if (fz % fm == 0) {
if (fz != fm) printf("%d*", fz / fm);
printf("sqrt(%d)\n", gen);
} else {
int k = gcd(abs(fz), abs(fm));
if (fz / k != 1) printf("%d*", fz / k);
printf("sqrt(%d)/%d\n", gen, fm / k);
}
}
}
return 0;
}