跳到正文

个人记录

赛后总结

QCX_2013约 4 分钟
原文

这是 2025年9月27日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2024年10月6日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 4 分钟

版本

  1. v2当前
  2. v1

得到剩余

略

C++
#include<bits/stdc++.h>
using namespace std;
double a,b;
int x;
int main(){
	cin>>a>>b;
	x=a/b;
	if(a<b){
		cout<<fixed<<setprecision(2)<<a;
		return 0;
	}
	if(a-b==0){
		cout<<"0.00";
		return 0;
	}
	cout<<fixed<<setprecision(2)<<a-(b*x);
	return 0;
}

乘积

比赛时脑残用质数一个个判断导致TLE,正解最多只需要双重循环

C++
#include<bits/stdc++.h>
using namespace std;
long long t,x,a[100005];
void pan(long long x){
	long long cnt=0;
	if(x<10){
		cout<<10+x<<endl;
		return ;
	} 
	for(int i=9;i>=2;i--){
		while(x%i==0){
			cnt++;
			a[cnt]=i;
			x/=i;
		}
	}
	if(cnt==0||x>=10){
		cout<<"-1"<<endl;
		return ;
	}
	sort(a+1,a+1+cnt);
	for(int i=1;i<=cnt;i++){
		cout<<a[i];
	}
	cout<<endl;
}
int main(){
	cin>>t;
	while(t--){
		cin>>x;
		pan(x);
	}
	return 0;
}

生肖属性

需要先假定一个年份,再一个个模拟

C++
#include<bits/stdc++.h>
using namespace std;
int n;
string animals[12] = {"Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig", "Rat"};
map<string,int>born;
string get_animal(int year){
	int a=0,y=2000;
	while(y<year){
		y++;
		a++;
		if(a==12){
			a=0;
		}
	
	}
	while(y>year){
		y--;
		a--;
		if(a==-1){
			a=11;
		}
	}
	return animals[a];
}
int main(){
	born["Bessie"]=2000;
	cin>>n;
	string sta,b1,in,re,an,year,from,stb;
	for(int i=1;i<=n;i++){
		cin>>sta>>b1>>in>>re>>an>>year>>from>>stb;
		born[sta]=born[stb];
		while(1){
			if(re=="previous") born[sta]--;
			else born[sta]++;
			if(get_animal(born[sta])==an) break;
		}
	}
	cout<<abs(born["Bessie"]-born["Elsie"]);
	return 0;
}

指导

该题是一道隐性二分,只需要写出正确的判断条件函数,就可以写出题目

C++
#include<bits/stdc++.h>
using namespace std;
int n,m,a[10000005];
bool check(long long k){
	long long cnt=0;
	for(int i=1;i<=n;i++){
		cnt+=(k-1+a[i])/a[i];
	}
	return cnt>=m;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	long long l=-1,r=m*100000ll; 
	while(l+1<r){
		long long mid=(r+l)/2;
		if(check(mid)==true){
			r=mid;
		}else{
			l=mid;
		}
	}
	l++;
	int last=0;
	for(int i=1;i<=n;i++){
		last+=(l-2+a[i])/a[i];
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if((l-1)%a[i]==0){
			last++;
			if(last==m){
				ans=i;
				break;
			}
		}
	}
	cout<<ans;
	return 0;
}