浙江理工大学 2024 年程序设计竞赛
因本人很菜,题解只能写五个,按照做题难易先后顺序写,题解顺序为L、G、I、F、A
L 今天是个上分的好日子
题解:给出一段01串代表每把游戏的输赢,赢了+3,输了-12,有连胜机制,连胜六把内没把会加n-1分,大于六把每次加5分,输出一共得了多少分。直接模拟即可
代码:
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string as;
cin>>as;
long long con1=0;
long long sum1=0;
for(int i=0;i<as.size();i++)
{
if(as[i]=='1')
{
con1++;
if(con1>=2&&con1<=6)
{
sum1+=(con1-1);
}
if(con1>6)
{
sum1+=5;
}
sum1+=3;
}
else
{
con1=0;
sum1-=12;
}
}
cout<<sum1;
return 0;
}
G 好想会数学啊
题解:求第一个大于 10^30+50 的质数。比赛时没有思路,就顺着试了两个数 51,57…
代码:
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string ch = "100000000000000000000000000057";
cout << ch << endl;
return 0;
}
I神说要有光
题解:给出一个字符矩阵,初始全部为a,给出q个操作,按照相应的操作执行即可。模拟题,按照题目意思模拟即可。
代码:
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
char as[1005][1005];
int n,q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
cin >> q;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
as[i][j] = 'a';
}
}
while(q--)
{
int s;
int a;
char b;
cin >> s;
if(s == 5)
{
int x;
cin >> x;
for(int i = 1; i <= n; i++)
{
cout << as[x][i];
}
cout << endl;
}
else
{
cin >> a >> b;
}
if(s == 1)
{
for(int i = 1; i <= n; i++)
{
as[a][i] = b;
}
}
if(s == 2)
{
for(int i = 1; i <= n; i++)
{
as[i][a] = b;
}
}
if(s == 3)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if((i + j) == a)
as[i][j] = b;
}
}
}
if(s == 4)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if((i - j) == a)
as[i][j] = b;
}
}
}
}
return 0;
}
F leetcode
题解:给出一串字符串,求出每个字符串中第一个leetcode子序列的终止位置,若不存在则输出0。本题思路了:定义两个string,一个接受读入字符串,一个赋“leetcode”用于判断,定义标志量flag判断是否存在子串“leetcode”,利用string中自带的find函数,循环8次,每次判断能否在输入字符串中找到对应的字符(用t接受下标位置,看能否找到),找不到直接输出0,否则输出找的最后一个e的下标加一。
代码:
#include<iostream>
using namespace std;
int dp[10];
int main()
{
string s;
cin >> s;
int len = s.size();
string ch = "leetcode";
int t;
int idx;
bool flag = false;
for(int i = 0; i < len; i++)
{
idx = i;
for(int j = 0; j <= 7; j++)
{
t = s.find(ch[j],idx);
if(t == -1)
{
cout << 0 << ' ';
flag = true;
break;
}
else idx = t+1;
}
if(!flag)
{
cout << t + 1<< ' ';
}
}
return 0;
}
A 春天到了,该练习 dp 了
题解:给出多组序列,每组序列给出q次询问,每次询问给出三个整数l,r,k,按照题目中所给出的状态转移式,求出dp[ i ] [ j ] 的值。
代码:
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
ll a[N],b[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t;
cin >>t;
while(t--)
{
int n;
cin >> n;
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
cin >> a[i];
a[i]+=a[i-1];
b[i]+=b[i-1]+i*i;
}
int k;
cin >> k;
while(k--)
{
int l,r,kk;
cin >> l >> r>> kk;
ll ans,m=r-l+1;
ans=a[r]-a[l-1]+b[m]-b[m-kk];
cout<<ans<<'\n';
}
}
return 0;
}