跳到正文

个人记录

8.29_407_课堂总结

Railgun_约 5 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

U594497 名称称

100pts\color{52c41a} 100pts

思路

特别简单模拟

代码

C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string ans = "";
	for(int i = 1; i <= 8; i++){
		for(int j = 1; j <= 8; j++){
			char c;
			cin >> c;
			if(c == '*'){
				ans = (char)(97 + j - 1);
				ans += (char)(57 - i);
			}
		}
	}
	cout << ans;
	return 0;
}

U594502 数列列

100pts\color{52c41a} 100pts

思路

阉割版A - B数对P1102

ai−aj=xa_i - a_j = x 可优化成 x+ai=ajx + a_i = a_j

因为可以 i=ji = j,所以直接一个 forfor 循环遍历ii,然后 lower_boundlower\_bound 找 jj(数组先排序)

代码

C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[200001];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, x;
	cin >> n >> x;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	stable_sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++){
		int f = x + a[i];
		if(a[lower_bound(a + 1, a + n + 1, f) - a] == f){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

T661997 [NOIP 2003 普及组] 乒乓球

80pts\color{52c41a} 80pts

思路

模拟,每次记录分数,当某方达到 1111 / 2121 分且分差大于 22 时记录一局,当结束时再记录一次

坑点:当结束时如果刚好下一局,就算是 0:00:0 也要输出

代码

C++
#include<bits/stdc++.h>
#define ll long long
#define st first
#define nd second
using namespace std;
map<int, pair<int, int>> m11, m21;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int h1 = 0, d1 = 0, h2 = 0, d2 = 0, c1 = 0, c2 = 0;
	while(1){
		char c;
		cin >> c;
		if(c == 'W'){
			h1++, h2++;
		}else if(c == 'L'){
			d1++, d2++;
		}
		if(h1 >= 11 || d1 >= 11){
			if(abs(h1 - d1) >= 2){
				m11[++c1] = {h1, d1};
				h1 = 0, d1 = 0;
			}
		}
		if(h2 >= 21 || d2 >= 21){
			if(abs(h2 - d2) >= 2){
				m21[++c2] = {h2, d2};
				h2 = 0, d2 = 0;
			}
		}
		if(c == 'E'){
				m11[++c1] = {h1, d1};
				m21[++c2] = {h2, d2};
			break;
		}
	}
	for(auto x : m11){
		cout << x.nd.st << ":" << x.nd.nd << "\n";
	}
	cout << "\n";
	for(auto x : m21){
		cout << x.nd.st << ":" << x.nd.nd << "\n";
	}
	return 0;
}

U594511 二进制猜猜

18pts\color{e74c3c} 18pts

思路

贪心,首先转换一下十进制,然后每次如果遇到 ?? 能取 11 就取 11

注意:一定要从高位开始否则会错

Hack:

输入:

代码
?10??
24

目标输出:

代码
24
//S = 11000

从低位开始的输出

代码
10
//S = 01011 / 1011

代码

C++
#include<bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
signed main(){
	int n;
	ll l;
	string s;
	cin >> s >> n;
	int wq = 1, he = 0;
	for(int i = s.size() - 1; i >= 0; i--){
		if(s[i] == '1'){
			he += wq;
		}
		wq *= 2;
	}
	wq /= 2;
    if(he > n){
        cout << -1;
        return 0;
    }
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '?'){
			if(he + wq <= n){
				he += wq;
			}
		}
		wq /= 2;
	}
	cout << he;
	return 0;
}
原文