跳到正文

个人记录

第3次课堂总结

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

文章信息

收录
2025年12月12日
更新
2026年7月13日
篇幅
约 3 分钟

版本

  1. v1当前

赵神牛的游戏

错因

没有特判伤害为0。

思路

模拟每个技能能否杀死 boss。

C++
#include<bits/stdc++.h>
long long n,m,a[100000001],k,f,x,y;
using namespace std;
int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if((x==0&&y!=0)||n/x*y>=k){//技能能否杀死 boss
			cout<<i<<" ";
			f++;
		}
	}
	if(f==0)cout<<-1;
	return 0;
}

最大公约数和最小公倍数问题

错因

q考虑不当,超时。

思路

枚举每个最大公约数和最小公倍数的可能

C++
#include<bits/stdc++.h>
long long n,m,a[10000001],k,f,y;
using namespace std;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int j=n*m/i;
		if(__gcd(i,j)==n&&i*j/__gcd(i,j)==m){//枚举每个最大公约数和最小公倍数
			f++;
		}
	}
	cout<<f;
	return 0;
}

Lemonade Line S

错因

时间不够。

思路

sort+循环判断

C++
#include<bits/stdc++.h>
long long n,m,a[10000001],k,f,y;
long long q(long long x,long long y) {
	return x>y;
}
using namespace std;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n,q);
	for(int i=1;i<=n;i++){
		if(a[i]>=f)f++;
		else break;
	}
	cout<<f;
	return 0;
}

玩具谜题

错因

时间不够。

思路

循环判断

C++
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,f,y,x;
struct noed{
	long long o;
	string nm;
}a[1000001];

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i].o>>a[i].nm;
	}
	f=1;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(x==0){
			if(a[f].o==0)f-=y;
			else f+=y;
		}else{
			if(a[f].o==0)f+=y;
			else f-=y;
		}
		f = (f + n) % n;
		if(f == 0){
			f = n;
		}
	}
	cout<<a[f].nm;
	return 0;
}
原文