9.17 CSP-J模拟赛错题情况总结
- problem 1今年还是明年
给定条日志日期和一个巡检日,需要求出严格晚于日志日期的下一个巡检日的年份 。
考试 分代码
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("hint.in","r",stdin);
freopen("hint.out","w",stdout);
int q,a,b;
scanf("%d %d %d",&q,&a,&b);
int y,m,d;
for(int i = 1;i <= q;i++){
cin >> y >> m >> d;
if((m == a && d < b) || (m < a)){
printf("%d\n",y);
}
else{
printf("%d\n",y + 1);
}
}
return 0;
}正解代码
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("hint.in","r",stdin);
freopen("hint.out","w",stdout);
int q,a,b;
scanf("%d%d%d",&q,&a,&b);
int y,m,d;
while(q--){
scanf("%d%d%d",&y,&m,&d);
if(m < a || (m == a && d < b)){
printf("%d\n",y);
}
else{
printf("%d\n",y + 1);
}
}
return 0;
}错因总结
考试时算法无误,但未取消同步或改为,输入输出时间过长,导致;
- problem 2左右为难
有座塔,给定每种塔的类型,具体为:
将这 座塔分成 和 两个区间,求左区间的进攻值之和 和右区间的防守值之和 差值的绝对值的最小值。
考试 分代码
#include <bits/stdc++.h>
using namespace std;
unsigned long long sumw[100005],sumv[100005];
int main(){
freopen("spearshield.in","r",stdin);
freopen("spearshield.out","w",stdout);
int n;
string s;
cin >> n >> s;
for(int i = 0;i < n;i++){
if(s[i] == '0'){
sumw[i + 1] = sumw[i] + i + 1;
sumv[i + 1] = sumv[i];
}
else if(s[i] == '1'){
sumw[i + 1] = sumw[i];
sumv[i + 1] = sumv[i] + i + 1;
}
// printf("w:%d v:%d\n",sumw[i + 1],sumv[i + 1]);
}
unsigned long long ans = sumv[n];
for(int p = 1;p <= n;p++){
ans = min(ans,(unsigned long long)abs(sumw[p] - (sumv[n] - sumv[p])));
}
cout << ans;
return 0;
}正解代码
#include <bits/stdc++.h>
using namespace std;
long long sumw[100005],sumv[100005];
int main(){
freopen("spearshield.in","r",stdin);
freopen("spearshield.out","w",stdout);
int n;
string s;
cin >> n >> s;
for(int i = 0;i < n;i++){
if(s[i] == '0'){
sumw[i + 1] = sumw[i] + i + 1;
sumv[i + 1] = sumv[i];
}
else if(s[i] == '1'){
sumw[i + 1] = sumw[i];
sumv[i + 1] = sumv[i] + i + 1;
}
// printf("w:%d v:%d\n",sumw[i + 1],sumv[i + 1]);
}
long long ans = sumv[n];
for(int p = 1;p <= n;p++){
ans = min(ans,(long long)abs(sumw[p] - (sumv[n] - sumv[p])));
}
cout << ans;
return 0;
}错因总结
我认为我本身没有大体上的错误,该题测评机不允许使用中间使用 在Devc++中编译成功,但测评机判定
-problem 3一圈又一圈
有许多个信标 ,其中 的位置为 。
从 开始,每个信标都是由上一个信标移动而来,移动顺序为 循环,移动距离为 给定 次询问,每次询问 的位置或区间 之间移动的距离。
考试 分代码
#include <bits/stdc++.h>
using namespace std;
unsigned long long sum[1000005];
int main(){
freopen("seek.in","r",stdin);
freopen("seek.out","w",stdout);
int q;
cin >> q;
int x,n,l,r;
for(int i = 2;i <= 1e6 + 3;i++){
sum[i] = sum[i - 1] + (i + 1) / 2;
}
while(q--){
cin >> x;
if(x == 1){
cin >> n;
int nx,ny;
if(n % 4 == 1){
nx = n / 4 + 1;
ny = -(n / 4);
}
else if(n % 4 == 2){
ny = -(n / 4) + ((n + 1) / 2);
nx = n / 4 + 1;
}
else if(n % 4 == 3){
ny = -(n / 4) + ((n + 1) / 2) - 1;
nx = ((n + 1) / 4) - (n + 1) / 2;
}
else if(n % 4 == 0){
nx = n / 4 - (n / 2);
ny = -(n / 4);
}
cout << nx << ' ' << ny << endl;
}
else if(x == 2){
cin >> l >> r;
cout << sum[r] - sum[l - 1] << endl;
}
}
return 0;
}正解代码
#include <bits/stdc++.h>
using namespace std;
unsigned long long sum[1000005];
int main(){
freopen("seek.in","r",stdin);
freopen("seek.out","w",stdout);
int q;
cin >> q;
int x,n,l,r;
for(int i = 1;i <= 1e6 + 3;i++){
sum[i] = sum[i - 1] + i / 2 + 1;
}
while(q--){
cin >> x;
if(x == 1){
cin >> n;
int nx,ny;
if(n % 4 == 1){
nx = n / 4 + 1;
ny = -(n / 4);
}
else if(n % 4 == 2){
ny = -(n / 4) + ((n + 1) / 2);
nx = n / 4 + 1;
}
else if(n % 4 == 3){
ny = -(n / 4) + ((n + 1) / 2) - 1;
nx = ((n + 1) / 4) - (n + 1) / 2;
}
else if(n % 4 == 0){
nx = n / 4 - (n / 2);
ny = -(n / 4);
}
cout << nx << ' ' << ny << endl;
}
else if(x == 2){
cin >> l >> r;
cout << sum[r - 1] - sum[l - 1] << endl;
}
}
return 0;
}错因总结
该题由于时间不够,虽然发现前缀和部分有问题,却来不及修改。坐标计算完全正确,没有修改,导致。
-problem 4异或
给定一个全部 的数组和一种操作:
输入 选择所有 并定义 。如果 , ,求 次操作后的数组。
考试 分代码
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[5000005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("xor.in","r",stdin);
freopen("xor.out","w",stdout);
int n,m;
int l,r,p,q;
cin >> n >> m;
for(int i = 1;i <= m;i++){
cin >> l >> r >> p >> q;
for(int t = l;t <= r;t++){
int j = t ^ p;
if(0 <= j && j < n){
a[j] = a[j] ^ q;
}
}
}
for(int i = 0;i < n;i++){
cout << a[i] << ' ';
}
return 0;
}暴力 分代码
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[5000005];
int main(){
freopen("xor.in","r",stdin);
freopen("xor.out","w",stdout);
unsigned int n,m;
unsigned long long int l,r,p,q;
cin >> n >> m;
while(m--){
cin >> l >> r >> p >> q;
for(int i = l;i <= r;i++){
unsigned long long j = i ^ p;
if(j < (unsigned long long)n){
a[j] = a[j] ^ q;
}
}
}
for(int i = 0;i < n;i++){
if(i) cout << ' ';
cout << a[i];
}
return 0;
}错因总结
本题正解极难,为 CSP-S 的题目,暴力60分即可。在考试中,代码仅考虑了数组类型,并未考虑 的范围,未使用 ,导致 分