跳到正文

个人记录

7.29日来追梦训练课总结

ChenJianan14约 6 分钟
原文
文章信息与版本

文章信息

发布
2025年7月29日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 6 分钟

版本

  1. v1当前

陈建安的总结

共七道题我错的题是T2、T3、T4、T5、T6、T7。

T2

错误原因:

细节错误。

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
int k,cnt,s;
int main(){
	cin >> k;
	for(int i=1;;i++){
		for(int j=1;j<=i;j++){
			s+=i,cnt++;
			if(cnt==k){
				cout << s;
				return 0;
			}
		}
		
	}
	return 0;
}  

T3

错误原因:

没思路。

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
int a[135][135],x,y,k,d,n,maxx,s,cnt;
int main(){
	cin >> d >> n;
	for(int i=1;i<=n;i++){
		cin >> x >> y >> k;
		a[x][y]=k;
	}
	for(int i=0;i<=128;i++){
		for(int j=0;j<=128;j++){
			s=0;
			for(int h=max(0,i-d);h<=min(128,i+d);h++){
				for(int l=max(0,j-d);l<=min(128,j+d);l++)s+=a[h][l];
			}
			if(s>maxx)maxx=s,cnt=1;
			else if(s==maxx)cnt++;
		}
	}
	cout << cnt <<" "<< maxx;
	return 0;
}  

T4

错误原因:

代码错误。

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
queue<int>q;
int n,m,d;
int main(){
	cin >> n >> m;
	for(int i=1;i<=n;i++)q.push(i);
	while(q.size()!=0){
		d++;
		if(d==m){
			cout << q.front()<<" ";
			q.pop();
			d=0;
		}
		else{
			q.push(q.front());
			q.pop();
		}
	}
	return 0;
}  

T5

错误原因:

没思路。

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
struct st{
	int h;
	int t;
}s[2005];
int cmp(st s1,st s2){
	if(s1.h==s2.h)return s1.t<s2.t;
	return s1.h<s2.h;
}
int a[10],n,cnt;
int main(){
	cin >> n;
	for(int i=1;i<=n;i++)cin >> s[i].h>>s[i].t;
	sort(s+1,s+1+n,cmp);
	for(int i=1;i<=n;i++){
		if(a[s[i].h]==0)cnt++,a[s[i].h]=s[i].t;
		else{
			if(s[i].t-a[s[i].h]>=60)cnt++,a[s[i].h]=s[i].t;
		}
	}
	cout << cnt;
	return 0;
}  

T6

错误原因:

没思路。

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
long long n;
int cheak(int x)
{
    int mg=0;  
    int bg=0; 
    int sy=x; 
    while(1){
        bg+=sy;  
        mg+=sy; 
        sy=0; 
        sy+=mg/3; 
        mg%=3;   
        if(sy==0)break;
    }
    if(bg>=n)return 1;
    else return 0;
}
int main(){
    cin>>n;
    long long l=0, r=100000005;
    while(l+1<r){
        long long mid=(l+r)/2;
        if( cheak(mid) == 1)r=mid;
        else l=mid;
    }
    cout<<r;
    return 0;
}

T7

错误原因:

没思路。

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
long long cd, nian, yue, ri, shi, fen, miao;
int a[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void cheak() {
    if (nian % 4 == 0 && nian % 100 != 0 || nian % 400 == 0)a[2] = 29;
    else a[2] = 28;
}
int main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> cd >> nian >> yue >> ri >> shi >> fen >> miao;
        long long time = (1LL << (cd - 1)) - 1; 
        miao += time;
        fen += miao / 60;
        miao %= 60;      
        shi += fen / 60; 
        fen %= 60;    
        ri += shi / 24; 
        shi %= 24;  
        if (yue == 2) cheak();
        while (ri > a[yue]) { 
            ri -= a[yue];     
            yue++;         
            if (yue > 12) {  
                nian++;      
                yue = 1;     
            }
            if (yue == 2) cheak();
        }
        
        cout << nian << " " << yue << " " << ri << " " 
             << shi << " " << fen << " " << miao << endl;
    }
    
    return 0;
}
原文