A、AKU NEGARAKU
约瑟夫环裸题
AC代码
#include<iostream>
#include<stdio.h>
using namespace std;
#define ll long long
ll yuesefu(ll n, ll m) {
if (n == 1) {
return 0;
}
else {
return (yuesefu(n - 1, m) + m) % n;
}
}
int main(void) {
int a, b;
while (cin >> a >> b && a + b != 0) {
cout << yuesefu(a, b) + 1 << endl;
}
return 0;
}
C、ELI’S CURIOUS MIND
一个假的dp
AC代码
#include<stdio.h>
#define ll long long
int main()
{
int n, t = 1;
ll dp[100];
dp[0] = 0; dp[1] = 1; dp[2] = 1;
for (int i = 3; i < 80; i++)
dp[i] = dp[i - 2] + dp[i - 3];
dp[1] = 0; dp[2] = 0;
while (scanf("%d", &n) && n) {
printf("Case #%d: ", t++);
ll res = dp[n] + dp[n - 1];
printf("%lld\n", res);
}
return 0;
}
D、EXPLORACE
最小生成树裸题
AC代码
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n, m, tot = 0, k = 0;
int fat[2000];
struct node
{
int from, to, dis;
}edge[200];
bool cmp(const node& a, const node& b)
{
return a.dis < b.dis;
}
int father(int x)
{
if (fat[x] != x)
return father(fat[x]);
else return x;
}
void unionn(int x, int y)
{
fat[father(y)] = father(x);
}
int main()
{
int t; scanf("%d", &t);
int nn = 1;
while (t--) {
//memset(fat, 0, sizeof(fat));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
scanf("%d%d%d", &edge[i].from, &edge[i].to, &edge[i].dis);
}
k = 0, tot = 0;
for (int i = 1; i <= n; i++) fat[i] = i;
sort(edge + 1, edge + 1 + m, cmp);//按权值排序(kruskal的体现)
for (int i = 1; i <= m; i++)//从小到大遍历
{
if (k == n - 1) break;//n个点需要n-1条边连接
if (father(edge[i].from) != father(edge[i].to))
{
unionn(edge[i].from, edge[i].to);//加入
tot += edge[i].dis;//记录边权
k++;
}
}
printf("Case #%d: %d meters\n", nn++, tot);
}
return 0;
}
E、MATRIX MULTIPLICATION CALCULATOR
矩阵相乘,暴力就可以过
AC代码
#include<stdio.h>
#include<string.h>
int a[25][25], b[25][25], c[25][25];
int main()
{
int x, y, x1, y1;
int t = 1;
while (scanf("%d%d%d%d", &x, &y, &x1, &y1) && x + y + x1 + y1 != 0) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++)
scanf("%d", &a[i][j]);
}
for (int i = 0; i < x1; i++) {
for (int j = 0; j < y1; j++)
scanf("%d", &b[i][j]);
}
printf("Case #%d:\n", t++);
if (y != x1) {
printf("undefined\n");
continue;
}
memset(c, 0, sizeof(c));
for (int i = 0; i < x; i++) {
for (int j = 0; j < y1; j++) {
for (int k = 0; k < y; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
for (int i = 0; i < x; i++) {
printf("| ");
for (int j = 0; j < y1; j++) {
printf("%d ", c[i][j]);
}
printf("|\n");
}
}
return 0;
}
F、SUM OF SUB RECTANGLE AREAS
推公式,由于是大数,拿python写的
AC代码
t = int(input())
for i in range(t):
n = int(input())
res = n * n - (n - 1) * n // 2 + n ** 3 - n * n * (n - 1) + (n - 1) * n * (2 * n - 1) // 6
res //= 2
res *= res
print(res)
G、WAK SANI SATAY
队友写的(非本人代码,仅供参考),买菜题
AC代码
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;
#define getT long long t;scanf("%lld",&t)
#define getN long long n;scanf("%lld",&n)
#define for0n(n) getN; for(long long i=0;i<n;i++)
#define for1n(n) getN; for(long long i=1;i<=n;i++)
#define for0(n) for(long long i=0;i<n;i++)
#define for1(n) for(long long i=1;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod;
ll gcd(ll a, ll b) {
return a % b == 0 ? b : gcd(b, a%b);
}
ll pow(ll a, ll b) {
ll an = 1;
ll base = a % mod;
while (b > 0) {
if (b & 1 != 0) {
an = (an*base) % mod;
}
base = (base*base) % mod;
b >>= 1;
}
return an % mod;
}
ll inv(ll a) {
return pow(a, mod - 2);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
ll Arithmetic(ll a1, ll n, ll d) {
ll sum = 0;
sum += n * a1;
sum %= mod;
ll temp = n * (n - 1);
temp %= mod;
temp *= d;
temp %= mod;
temp /= 2;
temp %= mod;
return (sum + temp) % mod;
}
ll euler(ll n)
{
ll ans = n;
for (ll i = 2; i*i <= n; i++)
if (n%i == 0)
{
ans = ans - ans / i;
while (n%i == 0)
n /= i;
}
if (n > 1)
ans = ans - ans / n;
return ans;
}
int main(void) {
getN;
ll cnt = 1;
const double base_num_stick = 85.0;
const double rate_a = 0.8-(15.5 / base_num_stick), rate_b =1.0-( 32.0 / base_num_stick), rate_c = 1.20-(40.0 / base_num_stick);
while (n)
{
double a, b, c, d;
double total = 0.0;
double ans = 0;
for0(n) {
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
total += a;
total += b;
total += c;
ans += a * rate_a;
ans += b * rate_b;
ans += c * rate_c;
ans += 0.60*d;
}
//ans -= total / 85.0*8.0;
printf("Case #%lld: RM%.2lf\n", cnt++, ans);
scanf("%lld", &n);
}
return 0;
}
H、STROOP EFFECT
将所有情况按照题目存在一个表中,只要现在这个新表和题目中的表成比例,即可刺激
AC代码
#include<stdio.h>
#include<string.h>
#include<map>
using namespace std;
int main()
{
int T; scanf("%d", &T);
int tbb[5][5];
for (int ca = 1; ca <= T; ca++) {
int x, m = 0, n = 0, nm = 0, nn = 0;
int tb[5][5];
memset(tb, 0, sizeof(tb));
int flag = 0;
while (scanf("%d", &x) && x) {
int a = x / 10;
int b = x % 10;
tb[a][b]++;
if (a != m) {
nm = 1;
m = a;
}
else
nm++;
if (b != n) {
nn = 1;
n = b;
}
else
nn++;
if (nm >= 3 || nn >= 3)
flag = 1;
}
if (flag) {
printf("Case #%d: Not Stroop\n", ca);
continue;
}
int p;
if (tb[1][1] % 3 == 0) {
p = tb[1][1] / 3;
}
else {
printf("Case #%d: Not Stroop\n", ca);
continue;
}
int f = 0;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
if (i == j) {
if (tb[i][j] % 3 == 0) {
if (p != tb[i][j] / 3)
f = 1;
}
else
f = 1;
}
else {
if (p != tb[i][j])
f = 1;
}
}
}
if (f)
printf("Case #%d: Not Stroop\n", ca);
else
printf("Case #%d: Stroop\n", ca);
}
return 0;
}
J、VIRUS OUTBREAK
大数斐波那契数列
AC代码
import java.math.BigInteger;
import java.util.Scanner;
public class Main{
public static void main(String args[]){
BigInteger a[] = new BigInteger[500];
Scanner cin = new Scanner(System.in);
a[1] = BigInteger.valueOf(1);
a[2] = BigInteger.valueOf(1);
for(int i = 3; i < 495; i++)
a[i] = a[i - 1].add(a[i - 2]);
int n = cin.nextInt();
while(n != -1){
System.out.println("Hour: " + n + ": " + a[n] + " cow(s) affected");
n = cin.nextInt();
}
}
}