跳到正文

个人记录

4.10

HouYizhou约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年4月15日
收录
2026年4月16日
更新
2026年11月11日
篇幅
约 4 分钟

版本

  1. v1当前

P15852 [蓝桥杯第二届国际赛] 猜拳

错误思路:

没有搞清楚加减

正确思路:

用if判断计算分别净赚多少钱

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int x,y,z;
	int ans1=0,ans2=0,ans3=0;
	while(n--){
		cin>>x>>y>>z;
		if(x==y and x!=z){
			if((x==0 and z==1) or (x==1 and z==2) or (x==2 and z==0)){
				ans1++,ans2++;
				ans3-=2;
			}else{
				ans1--,ans2--;
				ans3+=2;
			}
		}else if(x==z and x!=y){
			if((x==0 and y==1) or (x==1 and y==2) or (x==2 and y==0)){
				ans1++,ans3++;
				ans2-=2;
			}else{
				ans1--,ans3--;
				ans2+=2;
			}
		}else if(z==y and z!=x){
			if((z==0 and x==1) or (z==1 and x==2) or (z==2 and x==0)){
				ans3++,ans2++;
				ans1-=2;
			}else{
				ans3--,ans2--;
				ans1+=2;
			}
		}
	}
	cout<<ans1<<'\n'<<ans2<<'\n'<<ans3<<'\n';
	return 0;
}

P1693 [USACO19FEB] Sleepy Cow Herding B

错误思路:

没有思路

正确思路:

如果有两个数相差1,输出0和0,如果相差2,输出1和max(a[2]-a[1]-1,a[3]-a[2]-1),如果都不是就输出2和max(a[2]-a[1]-1,a[3]-a[2]-1)

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[10];
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	if(a[1]+1==a[2] and a[2]+1==a[3])cout<<0<<'\n'<<0;
	else if(a[1]+2==a[3] or a[2]+2==a[3])cout<<1<<'\n'<<max(a[2]-a[1]-1,a[3]-a[2]-1);
	else cout<<2<<'\n'<<max(a[2]-a[1]-1,a[3]-a[2]-1);
	return 0;
}

P1628 合并序列

错误思路:

没有思路

正确思路:

先排序,再找出所有答案

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s[100005],t;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	sort(s+1,s+1+n);
	cin>>t;
	string x[n+5];
	int cnt=1;
	for(int i=1;i<=n;i++){
		int f=0;
		for(int j=0;j<t.size();j++){
			if(t[j]!=s[i][j])f=1;
		}
		if(f==0)x[cnt]=s[i],cnt++;
	}
	cnt--;
	for(int i=1;i<=cnt;i++){
		cout<<x[i]<<'\n';
	}
	return 0;
}

T750196 月色的花园绿化

错误思路:

没有思路

正确思路:

用小根堆执行这两种操作,输出数量

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	int n;
	int x,y;
	cin>>n;
	while(n--){
		cin>>x>>y;
		if(x==1){
			q.push(y);
			cout<<q.size()<<'\n';
		}else{
			while(q.size()>0){
				if(q.top()<=y)q.pop();
				else break;
			}
			cout<<q.size()<<'\n';
		}
	}
	return 0;
}
原文