2023/2/23

2023/2/23

A 门牌制作

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
int ans=0;
void slove(){
	for(int i=1;i<=2020;i++){
		int x=i;
		while(x){
			if(x%10==2)ans++;
			x/=10;
		}
	}
	cout<<ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--){
		slove();
	}
	return 0;
}

B 既约分数

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
void slove(){
	int ans=0;
	for(int i=1;i<=2020;i++){
		for(int j=1;j<=2020;j++){
			if(gcd(i,j)==1)ans++;
		}
	}
	cout<<ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--){
		slove();
	}
	return 0;
}

C 蛇形填数

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
void slove(){
	int now=1,cnt=2;
	for(int i=2;i<20;i++){
		now+=cnt;
		cnt++;
		now+=cnt;
		cnt++;
	}
	now+=cnt+cnt+1-(cnt+1)/2;
	cout<<now;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--){
		slove();
	}
	return 0;
}

D 七段码

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
vector<int>to[15];
int ans=8,a[15],p[15];
void fid(int x,int l){
	p[x]=1;
	for(int i=0;i<to[x].size();i++){
		int y=to[x][i];
		bool pd=false;
		for(int j=1;j<=l;j++)if(y==a[j])pd=true;
		if(!pd||p[y])continue;
		fid(y,l);
	}
}
bool check(int l){
	memset(p,0,sizeof(p));
	fid(a[1],l);
	for(int i=1;i<=l;i++)if(!p[a[i]])return false;
	return true;
}
void dfs(int x,int y){
	if(x==8)return ;
	if(x>2){
		if(check(x-1))ans++;
	}
	for(int i=y+1;i<=7;i++){
		a[x]=i;
		dfs(x+1,i);
	}
}
int main(){
	to[1].push_back(2);
	to[1].push_back(3);
	to[2].push_back(1);
	to[2].push_back(4);
	to[2].push_back(5);
	to[3].push_back(1);
	to[3].push_back(4);
	to[3].push_back(6);
	to[4].push_back(2);
	to[4].push_back(3);
	to[4].push_back(5);
	to[4].push_back(6);
	to[5].push_back(4);
	to[5].push_back(7);
	to[5].push_back(2);
	to[6].push_back(4);
	to[6].push_back(3);
	to[6].push_back(7);
	to[7].push_back(6);
	to[7].push_back(5);
	dfs(1,0);
	cout<<ans;
	return 0;
} 

E 跑步锻炼

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
int mh[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
void slove(){
	int ans=0;
	int now=5;
	for(int y=2000;y<=2020;y++){
		if(y%4==0&&y%100!=0||y%400==0)mh[2]=29;
		else mh[2]=28;
		for(int m=1;m<=12;m++){
			if(y==2020&&m>10)break;
			for(int d=1;d<=mh[m];d++){
				if(y==2020&&m==10&&d>1)break;
				if(now==0||d==1)ans++;
				ans++;
				now++;
				now%=7;
			}
		}
	}
	cout<<ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--){
		slove();
	}
	return 0;
}

F 回文日期

在这里插入图片描述
因为要求的日期回文,所以可以直接求月和日通过翻转得到年。
将得到的回文日期存入vector中从小到大排序,查询时直接使用二分或upper_bound找大于当前字典序的下一个日期即可。

“11111111”也是ababbaba形回文日期
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
string sst="10000101",edt="89991231";
int mh[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
vector<string>mp1,mp2;
void getmp(){
	for(int m=1;m<=12;m++){
		string s=to_string(m);
		if(s.length()==1)s="0"+s;
		for(int d=1;d<=mh[m];d++){
			string ss=to_string(d);
			if(ss.length()==1)ss="0"+ss;
			ss=s+ss;
			string t=ss;
			reverse(t.begin(),t.end());
			ss=t+ss;
			mp1.push_back(ss);
		}
	}
	mp2.push_back("10100101");
	mp2.push_back("20200202");
	mp2.push_back("30300303");
	mp2.push_back("40400404");
	mp2.push_back("50500505");
	mp2.push_back("60600606");
	mp2.push_back("70700707");
	mp2.push_back("80800808");
	mp2.push_back("90900909");
	mp2.push_back("01011010");
	mp2.push_back("11111111");
	mp2.push_back("21211212");
	sort(mp1.begin(),mp1.end());
	sort(mp2.begin(),mp2.end());
}
void slove(){
	string s;
	cin>>s;
	int	i=upper_bound(mp1.begin(),mp1.end(),s)-mp1.begin();
	int j=upper_bound(mp2.begin(),mp2.end(),s)-mp2.begin();
//	cout<<mp1.size()<<" "<<mp2.size()<<" "<<i<<" "<<j<<endl;
	cout<<mp1[i]<<endl<<mp2[j]<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
	getmp();
	cin>>T;
	while(T--){
		slove();
	}
//	for(auto x0:mp1)cout<<endl<<x<<endl;
//	for(auto x:mp2)cout<<endl<<x<<endl;
	return 0;
}

H 成绩统计

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
void slove(){
	int n,j=0,y=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		if(x>=60)j++;
		if(x>=85)y++;
	}
	cout<<int(j*1.0/n*100+0.5)<<"%\n"<<int(y*1.0/n*100+0.5)<<"%";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--){
		slove();
	}
	return 0;
}

J 子串分析

在这里插入图片描述
每个子串中,每一种字符只有第一次出现时有贡献。
比如“bcdabcdabcd”中若取区间 [ 1->4 , 4->11 ]对于字符’a’都只有第四个位置上出现的’a’提供了一个贡献值。区间[ 5->8 , 8->11]对于字符’a’都只有第8个位置上的’a’提供了一个贡献值。
因此对于每一个字符’a’~'z’使用一个数组 lxt[] 存放上一次该字符出现的位置,对于每个字符s[i]可以提供的贡献值即为(i-lxt[s[i]-‘a’])*(n-i+1)

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
int lxt[30];
void slove(){
	string s;
	cin>>s;
	int n=s.length();
	ll ans=0;
	for(int i=1;i<=n;i++){
		int x=s[i-1]-'a';
		ans+=(i-lxt[x])*(n-i+1);
		lxt[x]=i;
	}
	cout<<ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--){
		slove();
	}
	return 0;
}

K 平面切分

在这里插入图片描述
若该直线不重复则ans++
若该直线与之前的直线有一个不重复的交点则ans++

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define f first
#define s second
typedef long long ll;
set<pair<double,double>>s;
ll ans=1;
void slove(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		if(s.count({x,y}))continue;
		ans++;
		s.insert({x,y});
		set<pair<double,double>>p;
		for(auto [xx,yy]:s){
			if(x==xx)continue;
			double px=(yy-y)/(x-xx);
			double py=x*px+y;
			p.insert({px,py});
		}
		ans+=p.size();
	}
	cout<<ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--){
		slove();
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值