总结

· · 个人记录

考试情况

题目编号(点击编号可跳转) 模拟赛分数
\color{black}{T1} 100
\color{black}{T2} 100
\color{black}{T3} 60
\color{black}{T4} 0
\color{black}{T5} 0
\color{black}{T6} (别点击这里,由于题目编号为T,是比赛赛题,无法退出比赛模式) 0

题目总结

正确思路

准备5个结构体,每个结构体存储两个变量id和num
再循环输入,定义

id=i\\num=\sum^{4}_{i=1}a_i

接着sort,定义cmp为:

bool cmp(node x,node y){
  return x.num>y.num
}

接着输出第一个node的id和num

正确代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
constexpr int N = 1e5,M=5*(1e5+5);
struct node{//结构体
    int id,num;
}q[N];
bool cmp(node x,node y){//排序函数
    return x.num>y.num;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    for(int i  =1;i<=5;i++){//输入
        for(int j  =1;j<=4;j++){
            int x;cin >> x;
            q[i].num+=x;//计算
        }
        q[i].id=i;
    }
    sort(q+1,q+1+5,cmp);//排序
    cout << q[1].id << ' ' << q[1].num;//输出
    return 0;
}

T2

正确思路

首先,题目都数据范围为:

1\le n\le10^2\\0\le a_i\le10

所以可以进行暴力枚举,因为时间复杂度为O_{n^2},也就是O_{10000},所以不会超,只需要一步一步去枚举输出就可以了

正确代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
constexpr int N = 1e5,M=5*(1e5+5);
int n,a[N];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;//输入
    for(int  i = 1;i<=n;i++) cin >> a[i];
    for(int i = 1;i<=n;i++){//暴力枚举(代码有暴力倾向)
        int x=0;
        for(int j = 1;j<i;j++){
            if(a[j]<a[i]) x++;
        }
        cout << x << ' ';//输出
    }
    return 0;
}

T3

错误原因

模拟补全

错误代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int d,n;
int a[256][256];
int main(){
    cin >> d >> n;
    for(int i  =1;i<=n;i++){
        int q,p,k;
        cin >> q >> p >> k;
        a[q][p]=k;
    }
    int maxn=0,maxm=0;
    for(int i = 1+d;i<=129-d;i++){
        for(int j = 1+d;j<=129-d;j++){
            int num=0;
            for(int x=i-d;x<=i+d;x++){
                for(int y=j-d;y<=j+d;y++){
                    num+=a[x][y];
                }
            }
            if(num>maxn){
                maxn=num;maxm=1;
            }else if(num==maxn) maxm+=1;

        }
    }
    cout << maxm << ' ' << maxn;
    return 0;
}

错误出在

    for(int i = 1+d;i<=129-d;i++){
        for(int j = 1+d;j<=129-d;j++){
            int num=0;
            for(int x=i-d;x<=i+d;x++){
                for(int y=j-d;y<=j+d;y++){
                    num+=a[x][y];
                }
            }
            if(num>maxn){
                maxn=num;maxm=1;
            }else if(num==maxn) maxm+=1;

        }

正确思路

先录入每个路口的公共场所人数,再在每个点模拟尝试安装信号塔能连接多少人,最后统计最大值

正确代码

#include<bits/stdc++.h>
using namespace std;
int d,n,a[200][200],x,y,ans,cnt;
void solve(int x,int y){//模拟安装信号塔
    int lx,rx,uy,dy,sum(0);
    lx = x-d;rx = x+d;uy = y+d;dy = y-d;
    if(lx<0) lx = 0;
    if(rx>128) rx = 128;
    if(uy>128) uy = 128;
    if(dy<0) dy=0;
    for(int i = lx;i<=rx;i++)
    for(int j = dy;j<=uy;j++){
        sum+=a[i][j];
    }
    if(sum== ans) cnt++;
    if(sum>ans){
        ans=sum;
        cnt=1;
    }
}
int main(){
    cin >> d >> n;
    for(int i = 1;i<=n;i++){
        cin >> x >> y >> a[x][y];//录入
    }
    for(int i = 0;i<=128;i++){
        for(int j=0;j<=128;j++){
            solve(i,j);//统计
        }
    }
    cout << cnt << ' ' << ans;//输出
    return 0;
}

T4

错误原因

骗分

错误代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
constexpr int N = 1e5,M=5*(1e5+5);
int t;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    while(t--) {
        cout << -1 << endl;
    }
    return 0;
}

错误出在

???我这是骗分代码

的 ???我这是骗分代码 处。

正确思路

先录入,判断

{sum}\mod{2}==1\\ \text{或}\\ {(2n-sum)}\mod{2}==1

如果是,就输出-1

否则定义A_i\not=B_i为sum1,否则为sum2
输出\frac{sum1+sum2}{2}+2(sum1\mod{2}\text{AND}sum2\mod{2})

正确代码

#include<bits/stdc++.h>
using namespace std;
int a[10005],b[10005];
int main(){
    int t;
    cin >> t;
    while(t--){//输入
        int n,sum = 0;
        cin >> n;
        for(int i = 1;i<=n;i++) {cin >> a[i];sum+=a[i];}
        for(int i = 1;i<=n;i++) {cin >> b[i];sum+=b[i];}
        if(sum%2||(n*2-sum)%2){//输出-1
            cout << "-1\n";
            continue;
        }
        int sum1 = 0,sum2 = 0;//统计
        for(int i = 1;i<=n;i++)
            if(a[i]!=b[i]){
                if(a[i]) sum1++;
                else sum2++;
            }
        cout << sum1/2+sum2/2+2*(sum1%2&&sum2%2) << endl;//输出
    }
    return 0;
}

T5

错误原因

骗分

错误代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
constexpr int N = 1e5,M=5*(1e5+5);

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << "1 5\n6 7\n8 9";
    return 0;
}

错误出在

???我这是骗分代码

的 ???我这是骗分代码 处。

正确思路

可以将数组A分成K个背包,然后求min(max{dp})

正确代码

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int a[N],nex[N],pre[N],n,k;
bool check(int mid){//k分
    int pos=k,sum=a[n];
    nex[pos]=n,pre[pos]=n;
    for(int i = n-1;i>=1;i--){
        if(sum+a[i]<=mid){
            sum+=a[i];
            pre[pos] = i;
        }
        else {
            pos --;
            if(pos==0){
                return 0;
            }
            sum=a[i];
            nex[pos]=i,pre[pos]=i;
        }
    }
    return 1;
}
int main(){
    cin >> n >> k;//输入
    int l  = 0,r=0;
    for(int i = 1;i<=n;i++){
        cin >> a[i];
        r+=a[i];
        l=max(l,a[i]);//统计l和r 
    }
    l--;r++;
    while(l+1<r){//二分
        int mid=l+r>>1;
        if(check(mid)){
            r=mid;
        }else l = mid;
    }
    check(r);
    for(int i=1;i<=k;i++) cout << pre[i] << ' ' << nex[i] << endl;//输出
    return 0;
}

T6

错误原因

骗分

错误代码

文件丢失

错误出在

骗分

的 骗分 处。

正确思路

先统计,再二分

正确代码

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int a[N],n,sum[N],m,c;
int main(){
    cin >> n >> m >> c;
    for(int i  = 1;i<=n;i++){
        int x;
        cin >> x;
        x++;
        a[x]++;
        a[x+m]++;
    }
    for(int  i = 1;i<=2*m;i++){
        sum[i]=sum[i-1]+a[i];
    }
    long long ans = 0;
    for(int i = 0;i<m;i++){
        int l = i,r=2*m+1;
        while(l+1<r){
            int mid = l+r>>1;
            if(sum[mid]-sum[i]>=c){
                r=mid;
            }else {
                l = mid;
            }
        }
        ans+=sum[r]-sum[i];
    }
    cout << ans;
    return 0;
}