A - Two Regular Polygons
问是否可以在一个正多边形内部内接一个正多边形,可以内接,分配给内部的多边形的每一条边的角度一样,对应的外部多边形的边数一样
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
int Gcd(int a,int b){if (b == 0) return a; return Gcd(b , a%b);}
int Lcm(int a, int b){ return a/Gcd(a,b)*b;}
inline long long read(){
long long f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e6 + 10;
int main(){
int T = read();
while(T--){
int n = read(),m = read();
if (n % m == 0) puts("YES");
else puts("NO");
}
return 0;
}
B - Bogosort
显然,倒着放一定满足条件
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
int Gcd(int a,int b){if (b == 0) return a; return Gcd(b , a%b);}
int Lcm(int a, int b){ return a/Gcd(a,b)*b;}
inline long long read(){
long long f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e6 + 10;
int a[maxn];
int main(){
int T = read();
while(T--){
int n = read();
for(int i=1; i<=n; i++){
a[i] = read();
}
sort(a + 1,a + n + 1);
for(int i=n; i>=1;i--){
printf("%d ",a[i]);
}
printf("\n");
}
return 0;
}
C - Adding Powers
判断一下,每一个数是不是k的次幂,并且没相同次幂即可
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
int Gcd(int a,int b){if (b == 0) return a; return Gcd(b , a%b);}
int Lcm(int a, int b){ return a/Gcd(a,b)*b;}
inline long long read(){
long long f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e6 + 10;
int cnt[maxn];
LL a[maxn];
int main(){
int T = read();
while(T--){
int n = read(),k = read(),tag = 1;
for(int i=0; i<=100; i++) cnt[i] = 0;
for(int i=1; i<=n; i++){
a[i] = read();
int pos = 0;
LL tmp = a[i];
while(tmp){
if (tmp % k > 1){
tag = 0;
}else{
if (tmp % k == 0){
}else{
cnt[pos]++;
if (cnt[pos] > 1) tag = 0;
}
}
pos++;
tmp /= k;
}
}
if (tag) puts("YES");
else puts("NO");
}
return 0;
}
D - Count the Arrays
m个里面选出n-1个,然后有n-2种情况复制一个,拿出最大的和两个复制的,剩下的n-3个数自己分配到左边还是右边,答案就是
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
int Gcd(int a,int b){if (b == 0) return a; return Gcd(b , a%b);}
int Lcm(int a, int b){ return a/Gcd(a,b)*b;}
inline long long read(){
long long f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e6 + 10;
const LL mod = 998244353 ;
LL C(LL n,LL m){
static LL M = 0,inv[maxn],mul[maxn],invMul[maxn];
while(M <= n){
if (M){
inv[M] = M == 1 ? 1 : (mod-mod/M)*inv[mod%M]%mod;
mul[M] = mul[M-1]*M%mod;
invMul[M] = invMul[M-1]*inv[M] % mod;
}else{
mul[M] = 1;
invMul[M] = 1;
}
M++;
}
return mul[n]*invMul[m] % mod * invMul[n-m]%mod;
}
LL qpow(LL a,int b){
LL ans = 1,base = a;
while(b){
if (b & 1) ans = ans * base % mod;
b >>= 1;
base = base * base % mod;
}
return ans % mod;
}
int main(){
int n = read(),m = read();
if (n == 2){
cout << 0 << endl;
return 0;
}
LL ans = C(m,n-1);
ans = ans * (n - 2) % mod;
ans = ans * qpow(2,n-3) % mod;
cout << ans << endl;
return 0;
}
E - Array Shrinking
区间dp,首先区间处理出区间是否可以合并成一个数,然后剩下的dp处理最短答案
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
int Gcd(int a,int b){if (b == 0) return a; return Gcd(b , a%b);}
int Lcm(int a, int b){ return a/Gcd(a,b)*b;}
inline long long read(){
long long f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e3 + 10;
int dp[maxn][maxn];
int ans[maxn];
int main(){
int n = read();
for(int i=1; i<=n; i++){
dp[i][i] = read();
}
for(int len = 2; len <= n; len++){
for(int l=1; l + len - 1 <= n; l++){
int r = l + len - 1;
for(int mid=l; mid <r; mid++){
if (dp[l][mid] && dp[mid+1][r] && dp[l][mid] == dp[mid+1][r]){
dp[l][r] = dp[l][mid] + 1;
}
}
}
}
for(int r=1; r<=n; r++){
ans[r] = r;
for(int l=r; l>=1; l--){
if (dp[l][r]){
ans[r] = min(ans[r],ans[l-1] + 1);
}
}
}
cout << ans[n] << endl;
return 0;
}
总结
D题卡了一下,没有那么快得出思路,E题有点菜,没想出来
来源:CSDN
作者:风声sp
链接:https://blog.csdn.net/CCCCTong/article/details/104774226