8.29_407_课堂总结
U594497 名称称
思路
特别简单模拟
代码
#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 数列列
思路
阉割版A - B数对P1102
因为可以
代码
#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 普及组] 乒乓球
思路
模拟,每次记录分数,当某方达到
坑点:当结束时如果刚好下一局,就算是
代码
#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 二进制猜猜
思路
贪心,首先转换一下十进制,然后每次如果遇到
注意:一定要从高位开始否则会错
Hack:
输入:
?10??
24
目标输出:
24
//S = 11000
从低位开始的输出
10
//S = 01011 / 1011
代码
#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;
}