跳到正文

学习·文化课

8/7

LED_light约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年8月7日
收录
2025年12月12日
更新
2026年11月5日
篇幅
约 3 分钟

版本

  1. v1当前

T4

思路

在读入xx和yy后直接枚举。

代码

C++
#include<bits/stdc++.h>
using namespace std;
int xx[1010][1010],yy[1010][1010];
int n,m,x,y;
void f(int x,int y){
	cout<<x<<' '<<y<<'\n';
	if(xx[x][y]==0&&yy[x][y]==0)
		return;	
	f(xx[x][y],yy[x][y]);
	return;
}
int main(){
	cin>>m>>n>>x>>y;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>xx[i][j]>>yy[i][j];
	f(x,y);
	return 0;
}

注意

是先输入mm,后输入nn(我绝对不会告诉你,我因此丢了60分)

T5

思路

简单的模拟题(为什么我在考场上没想到!!!)[doge]

代码

C++
#include<bits/stdc++.h>
using namespace std;
bool leap(int x) {
    return (x % 4 == 0 && x % 100 != 0) || (x % 400 == 0);
}
int a[3000],x,y;
int main(){
	cin>>x>>y;
	a[1900] = 6;//为了星期数可以简单地使用模运算,这里规定 a[i] = 0 为星期一,a[i] = 1 为星期二,以此类推,a[i] = 6 为星期日
	for (int i = 1901; i <= y; i++) {
    	if (leap(i)) // 判断是否为闰年
    	    a[i] = (a[i - 1] + 2) % 7;
    	else
    	    a[i] = (a[i - 1] + 1) % 7;
	}
	int ans=0;
	for (int i = x; i <= y; i++) {
	    if (a[i] == 5 || a[i] == 6) // 判断是否是周末
	        ans++;
	}
	cout<<ans;
	return 0;
}

亖因

没思路
请输入文本(已红温){\color{red} 请输入文本(已红温)}

T6

代码(思路在里面)

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[150005],b[150005],n,ans;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	sort(b,b+n);
	for(int i=0;i<n;i++){
		int lim=1;//lim为10的k-1次方
		for(int k=1;k<=10;k++){
			if(lim*10<a[i]){//小优化,如果a[i]>10^k,那就不用算
				lim*=10;
				continue;
			}
			int ps1=lower_bound(b,b+n,lim-a[i])-b;
			int ps2=lower_bound(b,b+n,lim*10-a[i])-b;
			ans+=k*(ps2-ps1);//计算 k*s[i][k]
			lim*=10;
			if(b[n-1]+a[i]<lim)break;//和上面差不多的小优化
		}
	}
	cout<<ans<<endl;
	return 0;
}

错因

考场上没理解题意

原文