第十二届市选总结
目标
-
估分:。
-
实际:。
-
不该丢的分:。
-
实际应得的分:。
题目反思
T1
解题思路
用 表示除数,每次跳过一种商的情况。
考试时忘输出换行了。
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T;
void solve() {
int n,m = 1;
map<int,int> ans;
scanf("%lld",&n);
ans[1] = 0;
int i = n;
while(i > 0) {
m++;
ans[m] = n / i;
i = ans[m] + 1;
i = n / i;
}
printf("%lld\n",m);
for(int i = 1; i <= m; i++) {
printf("%lld ",ans[i]);
}
printf("\n");
}
signed main() {
freopen("divide.in", "r", stdin);
freopen("divide.out", "w", stdout);
scanf("%lld",&T);
while(T--) {
solve();
}
return 0;
}
solve();
}
return 0;
}T2
解题思路
思维题。
最后两位是 的倍数,那所有前缀都是 的倍数。
最后一位是 的倍数,那所有前缀都是 的倍数。
特判 加删重复即可。
话虽然是这么说,但实现起来还是挺麻烦的。
考试时打的暴力,本以为能骗 分,结果才 分。
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
string a;
int ans;
signed main() {
freopen("timestr.in", "r", stdin);
freopen("timestr.out", "w", stdout);
cin >> a;
int n = a.size();
for(int i = 0;i < n; i++) {
int x = 0;
x = a[i] - '0' + (a[i - 1] - '0') * 10;
if(x % 4 == 0) {
ans += i;
if(a[i] == '0') {
ans++;
}
}
else if(a[i] == '0' or a[i] == '5') {
ans += i + 1;
}
if(a[i] == '4' or a[i] == '8') {
ans++;
}
}
printf("%lld",ans);
return 0;
}T3
解题思路
DFS秒了(不用剪枝)。
其实也没有这么简单。
列举坑:
- 记得删测试代码。
- 当你递归发现一条路可以达到终点时,靠标记return,不然就会多输出。
考试时DFS炸了。
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T;
int n;
int a[105][105],t;
bool bz[105][105];
int dx[7] = {0,0,0,1,1,-1,-1};
int dy[7] = {0,1,-1,0,-1,0,1};
void dfs(int x,int y,int col)
{
if(t) return;
if(y == n and col == -1) {
puts("Chen");
t = 1;
return;
}
if(x == n and col == 1) {
puts("Jimmy");
t = 1;
return;
}
bz[x][y] = 1;
for(int i = 1;i <= 6; i++)
{
int xx = x + dx[i],yy = y + dy[i];
if(xx >= 1 and xx <= n and yy >= 1 and yy <= n and a[xx][yy] == col and !bz[xx][yy])
{
dfs(xx,yy,col);
}
}
}
void solve() {
t = 0;
scanf("%lld",&n);
for(int i = 1;i <= 104;i++) {
for(int j = 1;j <= 104;j++) {
bz[i][j] = 0;
}
}
for(int i = 1;i <= n; i++) {
for(int j = 1;j <= n; j++) {
scanf("%lld",&a[i][j]);
}
}
for(int i = 1;i <= n; i++) {
if(a[i][1] == -1) {
dfs(i,1,-1);
if(t == 1) {
return;
}
}
}
for(int i = 1;i <= n; i++) {
if(a[1][i] == 1) {
dfs(1,i,1);
if(t == 1) {
return;
}
}
}
puts("yet");
}
signed main() {
freopen("chess.in", "r", stdin);
freopen("chess.out", "w", stdout);
scanf("%lld",&T);
while(T--) {
solve();
}
return 0;
}T4
解题思路
dp。
这道题有几个坑:
- 同学们组成的是一个环。
- Jimmy很偏心,他不一定先把糖果发给第一个人。
我们可以考虑贪心,设第 个人拿到糖果的最短时间为 ,先 找到第一个领糖果的人,设他的编号为 ,那么 ,接下来我们进行DP,转移方程为:
从 先求一遍 ,再求 。
注意,因为这是一个环,所以 是从 推过来的,所以要单独求。
最后从 先求一遍 就可以了。
Code
#include<bits/stdc++.h>
using namespace std;
long long n,p[200005],t[200005],ans[200005],T,mn=INT_MAX;
int main() {
freopen("share.in", "r", stdin);
freopen("share.out", "w", stdout);
scanf("%lld",&n);
for(register long long i = 1;i <= n; i++) {
scanf("%lld",&t[i]);
if(t[i] < mn) {
mn = t[i];
T = i;
}
}
for(register long long i = 1;i <= n; i++) {
scanf("%lld",&p[i]);
}
ans[T] = t[T];
for(register long long i = T + 1;i <= n; i++) {
ans[i] = min(ans[i - 1] + p[i - 1],t[i]);
}
ans[1] = min(ans[n] + p[n],t[1]);
for(register long long i = 2;i < T; i++) {
ans[i] = min(ans[i - 1] + p[i - 1],t[i]);
}
long long q,x;
scanf("%lld",&q);
for(register long long i = 1;i <= q; i++) {
scanf("%lld",&x);
printf("%lld\n",ans[x]);
}
return 0;
}T5 & T6
超纲。
End
总的来说,有许多分都不该扣,还是比赛做的太少了,经验不够,时间分配也不严谨。
CSP-J 争取过初赛。
RP++