CSP-J2025总结
这是第一次S和J可以同时参赛。
T1
很简单,把所有的数字找出来,然后从大到小输出即可。
可爱的代码^_^
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
vector<int> v;
bool cmp(int a,int b){
return a>b;
}
signed main(){
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
cin >> s;
n = s.length();
for(int i = 0;i < n;++ i){
if(s[i] >= '0'&&s[i] <= '9')
v.push_back(s[i]-'0');
}
sort(v.begin(),v.end(),cmp);
for(int i = 0;i < v.size();++ i)
cout << v[i];
return 0;
}
T2
也很简单,找一下小R是第几名,算一下就可以了。
可爱的代码w_w
#include<bits/stdc++.h>
using namespace std;
int read(){
int x = 0,y = 1;
char ch = getchar();
while(ch > '9'||ch < '0'){
if(ch == '-') y = -1;
ch = getchar();
}
while(ch >= '0'&&ch <= '9'){
x = x*10+ch-'0';
ch = getchar();
}
return x*y;
}
void print(int x){
char ch = x%10+'0';
if(x < 10){
printf("%c",ch);
return;
}
print(x/10);
printf("%c",ch);
}
int n,m;
int a[105];
bool cmp(int x,int y){
return x>y;
}
signed main(){
freopen("seat.in","r",stdin);
freopen("seat.out","w",stdout);
n = read();m = read();
for(int i = 1;i <= n*m;++ i)
a[i] = read();
int xr = a[1];
sort(a+1,a+1+n*m,cmp);
int w = 0;
for(int i = 1;i <= n*m;++ i){
if(a[i] == xr){
w = i;
break;
}
}
int ls = (w+n-1)/n;
int hs = w-(ls-1)*n;
if(ls%2 == 0) hs = n-hs+1;
print(ls);printf(" ");print(hs);
return 0;
}
T3
贪心。
从第一个开始,我们记录出现过哪些前缀异或和,每当有异或起来为\(k\)的时候,我们就以这个作为一段,再以这个的下一个为开始重新贪心,复杂度\(O(n)\)。
可爱的代码o_o
#include<bits/stdc++.h>
using namespace std;
int read(){
int x = 0,y = 1;
char ch = getchar();
while(ch > '9'||ch < '0'){
if(ch == '-') y = -1;
ch = getchar();
}
while(ch >= '0'&&ch <= '9'){
x = x*10+ch-'0';
ch = getchar();
}
return x*y;
}
void print(int x){
char ch = x%10+'0';
if(x < 10){
printf("%c",ch);
return;
}
print(x/10);
printf("%c",ch);
}
int n,k;
int a[500005];
int hav[2000005];
signed main(){
freopen("xor.in","r",stdin);
freopen("xor.out","w",stdout);
n = read();k = read();
for(int i = 1;i <= n;++ i)
a[i] = read();
int gs = 0;
for(int i = 1;i <= n;){
int sum = 0;hav[sum] = gs+1;
int j = i;
for(;j <= n;++ j){
sum ^= a[j];
if(hav[sum^k] == gs+1) break;
hav[sum] = gs+1;
}
i = j+1;
if(j <= n) gs++;
}
print(gs);
return 0;
}
T4
也是不算难。
首先先考虑比较好想的一个\(dp\),就是一个普通的\(01dp\)。
首先肯定要从小到大排序。
设\(dp_s\)代表总和为\(s\)的方案数,那么我们可以在这个往后的位置再找一个木棍,让那个木棍的长度小于\(s\)即可,记这样的木棍个数为\(x\),那么把\(dp_s*x\)累计到答案中。
这时候我们可以发现\(s > max{a_i}\)时是没用的,统一记在\(dp_{max{a_i}}\)中即可,那么我们的复杂度就优化为了\(O(n^2)\),就可以过了。
可爱的代码x_x
#include<bits/stdc++.h>
#define int long long
#define mod 998244353
using namespace std;
int read(){
int x = 0,y = 1;
char ch = getchar();
while(ch > '9'||ch < '0'){
if(ch == '-') y = -1;
ch = getchar();
}
while(ch >= '0'&&ch <= '9'){
x = x*10+ch-'0';
ch = getchar();
}
return x*y;
}
void print(int x){
char ch = x%10+'0';
if(x < 10){
printf("%c",ch);
return;
}
print(x/10);
printf("%c",ch);
}
int n;
int a[5005];
int f[5005][5005];
int q[5005];
int w[5005];
int m;
int ans;
signed main(){
freopen("polygon.in","r",stdin);
freopen("polygon.out","w",stdout);
n = read();
for(int i = 1;i <= n;++ i)
a[i] = read(),m += a[i];
sort(a+1,a+1+n);a[n+1] = a[n]+1;
for(int i = 1;i <= n+1;++ i)
for(int j = a[i-1]+1;j <= a[i];++ j)
w[j] = i-1;
f[0][0] = 1;
for(int i = 1;i <= n;++ i){
for(int j = 0;j <= a[n+1];++ j){
ans += f[i-1][j]*max(0ll,w[min(j+a[i],a[n+1])]-i)%mod;
ans %= mod;
}
for(int j = 0;j <= a[n+1];++ j){
f[i][j] += f[i-1][j];
f[i][j] %= mod;
f[i][min(j+a[i],a[n+1])] += f[i-1][j];
f[i][min(j+a[i],a[n+1])] %= mod;
}
}
print(ans);
return 0;
}

浙公网安备 33010602011771号