Problem A. Number Theory Problem

Solved.

水。

 #include<bits/stdc++.h>

 using namespace std;

 const int maxn = 1e5 + ;

 typedef long long ll;

 int n;
ll arr[maxn], ans[maxn]; void Init()
{
arr[] = ;
for(int i = ; i <= maxn; ++i)
{
arr[i] = (arr[i - ] * ) % ;
ans[i] = ans[i - ];
if(arr[i] == ) ans[i]++;
}
} int main()
{
Init();
int t;
scanf("%d",&t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%d", &n);
printf("Case #%d: %lld\n", cas, ans[n]);
}
return ;
}

Problem B. Hemi Palindrome

Unsolved.

题意:

定义$Hemi Palindrome$ 为去掉所有奇数位上的数字后是回文串或者去掉所有偶数位上的数是回文串,给出一个长度$N$

构造一个字典序最小的$Hemi Palindrome$

Problem C. Mr. Panda and Strips

Upsolved.

题意:

选择序列中两段不相交的连续区间,要求这两段区间并没有重复数字,求最长长度。

思路:

双指针枚举第一个区间,然后再左段和右段再双指针枚举最长的合并区间

我们考虑双指针扩展右指针的过程中,也可以更新答案

但是对于已经在前一个左指针上扩展过的,就没有必要扩展了。

.....L......R........

我们考虑枚举的时候是这样的

那么L.......R 这一段没有必要再检查是否有更大的答案,因为如果有,那么必然是L - 1........R 是更大的

 #include <bits/stdc++.h>
using namespace std; #define N 1010
#define M 100010
int t, n, a[N];
int vis[M][]; int solve(int ql, int qr)
{
int res = ;
for (int i = ql, r = ql - ; i <= qr; ++i)
{
if (r < i) r = i - ;
while (r < qr && !vis[a[r + ]][] && !vis[a[r + ]][])
{
++r;
vis[a[r]][] = ;
}
res = max(res, r - i + );
vis[a[i]][] = ;
}
return res;
} int main()
{
scanf("%d", &t);
for (int kase = ; kase <= t; ++kase)
{
printf("Case #%d: ", kase);
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%d", a + i);
memset(vis, , sizeof vis);
int res = ;
for (int i = , r = ; i <= n; ++i)
{
while (r < n && !vis[a[r + ]][])
{
++r;
vis[a[r]][] = ;
res = max(res, r - i + + max(solve(, i - ), solve(r + , n)));
}
int tmp = max(solve(, i - ), solve(r + , n));
res = max(res, r - i + + tmp);
vis[a[i]][] = ;
}
printf("%d\n", res);
}
return ;
}

Problem D. Ice Cream Tower

Solved.

题意:

要构造一个冰激凌塔,并且要求$第i层的尺寸需要 >=  第 i - 1 层的尺寸 \cdot 2$

给出n个冰激凌的尺寸,求最多构造多少个K层的塔

思路:

二分答案,贪心摆放。

 #include<bits/stdc++.h>

 using namespace std;

 typedef long long ll;
const int maxn = 3e5 + ; int n, k;
ll arr[maxn];
ll tower[maxn]; bool check(int mid)
{
int now = ;
for(int i = ; i <= mid; ++i) tower[i] = arr[now++];
for(int i = mid + ; i <= mid * k; ++i)
{
while(now <= n && arr[now] < tower[i - mid] * ) ++now;
if(now > n) return false;
tower[i] = arr[now++];
}
return true;
} int main()
{
int t;
scanf("%d", &t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%d %d", &n, &k);
for(int i = ; i <= n; ++i) scanf("%lld", arr + i);
sort(arr + , arr + + n);
int l = , r = n / k, res = ;
while(r - l >= )
{
int mid = (l + r) >> ;
if(check(mid))
{
l = mid + ;
res = mid;
}
else r = mid - ;
}
printf("Case #%d: %d\n", cas, res);
}
return ;
}

Problem E. Bet

Solved.

题意:

有一家赌球公司,你要赌球,对于每一支队伍 赔率是$A_i : B_i$

你要如何下注,使得如果有一只球队赢了,你就不会亏本,求你最多能下注的数量。

思路:

假设本金为1, 考虑对$第i支球队下注p_i 那么需要满足 p_i + p_i \cdot \frac{B_i}{A_i} > 1 $

移项之后即为$p_i > \frac{A_i}{A_i + B_i}$

那么对所有球队按这个式子从小到大排序,取到大于一就不取了

注意精度问题,数据保证小数点后最多三位,直接$ * 1000$

 #include<bits/stdc++.h>

 using namespace std;

 typedef long long ll;

 const double eps = 1e-;
const ll MOD = 1e9 + ;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + ; int n;
long double arr[maxn]; void RUN()
{
int t;
scanf("%d", &t);
for (int cas = ; cas <= t; ++cas)
{
scanf("%d", &n);
for (int i = ; i <= n; ++i)
{
long double ai, bi;
scanf("%Lf:%Lf", &ai, &bi);
ai = (int)(ai * + 0.1);
bi = (int)(bi * + 0.2);
arr[i] = ai / (ai + bi);
}
sort(arr + , arr + + n);
long double sum = ;
int cnt = ;
for (int i = ; i <= n; ++i)
{
sum += arr[i];
if (sum >= (long double)1.0) break;
cnt++;
}
printf("Case #%d: %d\n", cas, cnt);
}
} int main()
{
#ifdef LOCAL_JUDGE
freopen("Text.txt", "r", stdin);
#endif // LOCAL_JUDGE RUN(); #ifdef LOCAL_JUDGE
fclose(stdin);
#endif // LOCAL_JUDGE return ;
}

Problem F. Mr. Panda and Fantastic Beasts

Unsolved.

Problem G. Pandaria

Unsolved.

Problem H. Great Cells

Solved.

题意:

定义$Ag 矩阵中恰好有g个好点的方案数,定义好点为那一个点所在的行和列它最大,严格最大$

求$\sum_{i = 0}^{i = n * m} (g + 1) * A_g$

思路:

考虑将式子拆成

$\sum_{g = 0}^{g = n * m} g * A_g + \sum_{g = 0}^{g = n * m}A_g$

显然 右边的项的答案就是$k^{n * m}$

再考虑左边

如果我把式子 除以$\sum_{g = 1}^{g = n * m} A_g$

那么整个式子表达的含义即$g$  的数学期望

我们再考虑用另一种方法求数学期望

$E \cdot \sum_{g = 1}^{g = n * m} A_g = n * m * \sum_{i = 2}^{i = k} (i - 1) ^ {n + m - 2} \cdot k ^{(n - 1) * (m - 1)}$

含义是 令$i为好点的值,有多少种方案,那么显然,任意一个点都可以是好点,那么同行同列的取值为[1, i - 1]$

$其它格子的取值随意$

那么等式右边算出来的即是$所有g的总和$

 #include<bits/stdc++.h>

 using namespace std;

 typedef long long ll;

 const ll MOD = 1e9 + ;

 ll qpow(ll x, ll n)
{
ll res = ;
while(n)
{
if(n & ) res = res * x % MOD;
x = x * x % MOD;
n >>= ;
}
return res;
} int t;
int n, m, k; int main()
{
scanf("%d", &t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%d %d %d", &n, &m, &k);
ll ans = ;
for(int i = ; i <= k; ++i)
{
ans = (ans + n * m % MOD * qpow(i - , n + m - ) % MOD * qpow(k, (n - ) * (m - )) % MOD) % MOD;
}
ans = (ans + qpow(k, n * m)) % MOD;
printf("Case #%d: %lld\n", cas, ans);
}
return ;
}

Problem I. Cherry Pick

Unsolved.

Problem J. Mr.Panda and TubeMaster

Unsolved.

Problem K. Justice Rains From Above

Unsolved.

Problem L. World Cup

Solved.

水。

 #include<bits/stdc++.h>

 using namespace std;

 int arr[] = {, , };
int brr[] = {, , };
int ans[][][][]; void Init()
{
for(int i1 = ; i1 < ; ++i1)
{
for(int i2 = ; i2 < ; ++i2)
{
for(int i3 = ; i3 < ; ++i3)
{
for(int i4 = ; i4 < ; ++i4)
{
for(int i5 = ; i5 < ; ++i5)
{
for(int i6 = ; i6 < ; ++i6)
{
int a = arr[i1] + arr[i2] + arr[i3];
int b = brr[i1] + arr[i4] + arr[i5];
int c = brr[i2] + brr[i4] + arr[i6];
int d = brr[i3] + brr[i5] + brr[i6];
ans[a][b][c][d]++;
}
}
}
}
}
}
} int a, b, c, d; int main()
{
Init();
int t;
scanf("%d", &t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%d %d %d %d",&a, &b, &c, &d);
printf("Case #%d: ", cas);
if(a > || b > || c > || d > ) puts("Wrong Scoreboard");
else if(ans[a][b][c][d] > ) puts("No");
else if(ans[a][b][c][d]) puts("Yes");
else puts("Wrong Scoreboard");
}
return ;
}
05-18 05:50