CCPC 11.14 广州正赛
I (36min 1A)
开始的时候一直不知道哪一题签到,然后疯狂跟榜才发现。。。
打表即可发现规律
先暴力到10,然后可以发现规律
打表代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[15], sum[15];
int main()
{
for(int i = 1; i <= 10; i++) a[i] = i;
for(int i = 1; i <= 10; i++)
{
int cnt = 0;
for(int j = 1; j <= i; j ++) a[j] = j;
do{
memset(sum, 0, sizeof(sum));
bool flag = 1;
for(int k = 1; k <= i; k++)
{
sum[k] = sum[k - 1] + a[k] * 2;
if(sum[k] % k != 0)
{
flag = 0;
break;
}
}
if(flag) cnt++;
}while(next_permutation(a + 1, a + i + 1));
printf("%d\n", cnt);
}
return 0;
}
过题代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int T;
ll n;
ll qmi(ll a, ll b)
{
ll res = 1 % mod;
while(b)
{
if(b & 1) res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
ll solve(ll n)
{
if(n == 1) return 1;
if(n == 2) return 2;
if(n == 3) return 6;
ll res = qmi(2, n - 2);
res = res * 3 % mod;
return res;
}
int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%lld", &n);
ll res = solve(n);
printf("%lld\n", res);
}
return 0;
}
H (72min 2A)
题意:满足
x
m
o
d
y
=
a
x \mod y = a
x
m
o
d
y
=
a
y
m
o
d
z
=
b
y \mod z = b
y
m
o
d
z
=
b
z
m
o
d
x
=
c
z \mod x = c
z
m
o
d
x
=
c
给你
a
,
b
,
c
a,b,c
a
,
b
,
c
构造出x,y,z
不妨设
c
>
b
c > b
c
>
b
只要满足
z
=
c
z=c
z
=
c
y
=
k
∗
c
+
b
y=k*c+b
y
=
k
∗
c
+
b
x
=
k
∗
c
+
b
+
a
x = k * c + b + a
x
=
k
∗
c
+
b
+
a
选定合适的
k
k
k
即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int T;
ll a, b, c;
ll x, y, z, k;
int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%lld%lld%lld", &a, &b, &c);
if(a == 0 && b == 0 && c == 0) {puts("YES"); printf("1 1 1\n");}
else if(a == b && b == c && a > 0)
{
puts("NO");
}
else
{
if(c > b)
{
z = c;
k = max((ll)10, (a + c - 1) / c + 1);
y = k * c + b;
x = k * c + b + a;
}
else if(b > a)
{
y = b;
k = max((ll)10, (c + b - 1) / b + 1);
x = k * b + a;
z = k * b + a + c;
}
else if(a > c)
{
x = a;
k = max((ll)10, (b + a - 1) / a + 1);
z = k * a + c;
y = k * a + c + b;
}
puts("YES");
printf("%lld %lld %lld\n", x, y, z);
// bool ok = 0;
// if(x % y == a && y % z == b && z % x == c) ok = 1;
// if(ok) puts("!!!!!");
}
}
return 0;
}
C (4A)
与桂林类似,只要二分最后的答案即可。
很不幸wa了很多发
#include <bits/stdc++.h>
#define gc()(is==it?it=(is=in)+fread(in,1,Q,stdin),(is==it?EOF:*is++):*is++)
using namespace std;
typedef long long ll;
const int Q=(1<<24)+1;
const int N = 1000010;
char in[Q],*is=in,*it=in,c;
void read(long long &n){
for(n=0;(c=gc())<'0'||c>'9';);
for(;c<='9'&&c>='0';c=gc())n=n*10+c-48;
}
ll n, m;
ll a[N];
bool check(ll x)
{
ll minl = n - a[m] + a[1] - 1;
ll remain = 0;
ll loc = a[1];
ll cnt = 0;
for(int i = 1; i <= m - 1; i ++) {
ll t = x - remain;
if(t <= 0) return false;
if(a[i + 1] - a[i] <= t) {
ll d = min(minl, t - (a[i + 1] - a[i]));
cnt = cnt + d;
remain = 0;
loc = a[i + 1];
minl = minl - d;
minl = min(minl, loc - a[i] - 1);
}
else {
loc = a[i] + t;
remain = a[i + 1] - loc;
minl = min(minl, loc - a[i] - 1);
}
}
ll t = x - remain;
if(t >= n - a[m] + a[1]) return true;
else remain = n - a[m] + a[1] - t;
if(cnt >= remain) return true;
return false;
}
int main()
{
//scanf("%lld %lld", &n, &m);
//for(int i = 1; i <= m; i ++) scanf("%lld", &a[i]);
read(n), read(m);
//cout << n << " " << m << endl;
for(int i = 1; i <= m; i ++) read(a[i]);
//for(int i = 1; i <= m; i ++) cout << a[i] << endl;
if(m == 1) {
printf("%lld\n", n);
return 0;
}
ll r = 1e18, l = 1;
while(l < r) {
ll mid = l + r >> 1;
//cout << mid << endl;
if(check(mid)) r = mid;
else l = mid + 1;
}
printf("%lld\n", l);
return 0;
}
总体来说还是不错的,在金牌和银牌师兄的带领之下,我终于拿到了第一个铜牌,可喜可贺!!!
非常感谢师兄不嫌弃我。。。
未来继续加油吧