河南萌新联赛2024第(三)场:河南大学

题目链接:河南萌新联赛2024第(三)场:河南大学_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ

1.正则表达式

简单的 if 判断。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,sum=0;
int main()
{
	cin>>n;
	while(n--)
	{
		int x,x1,sign=0;
		char ch;
		for(int i=0; i<3; i++)
		{
			cin>>x>>ch;
			if(x>=0&&x<=255)
			{
				sign++;
			}
		}
		cin>>x1; 
		if(sign==3&&(x1>=0&&x1<=255))
		{
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}
 2.Circle

1.V圆的交点数:任意两个圆最多有2个交点. 对于n个圆,它们之间的交点数量由组合数:C(n,2)=n(n-1)

2.E圆的段数:若有k个交点,那么每个圆被分割成的段的数量为2+k(初始的1段加上k个交点) 

3.因此对于n个圆,每个圆的交点数为2(n-1)(即每个圆与其他n-1个圆交点造成的总交点数),圆被分段的总数量为:2(n-1)段,n个圆2n(n-1)段 。

欧拉公式为:V-E+F=2,其中: V:点(交点数) E:边(段数) F:面(区域数,包括外面的一个面)
即F=2n(n-1)+2-n(n-1)=n*n-n+2 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
int t;
int main()
{
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		if(n==0)
		{
			cout<<1<<" ";
		}
		else
		{
			cout<<n*n-n+2<<" ";
		}
	}
	return 0;
}
3.累加器

1.利用前缀和  (x→x+y)等价于(1→x+y)-(1→x)
2.发现规律:位变化=1.y处于2的幂位置当前位变化==自然数(具体看代码)+2.其他位置是二进制最小有效位的值(都能用2的幂来表示) 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
int c[2000010],f[2000010];
int fun(int x)//2.最小有效位
{
	return c[x&-x];
}

void init()
{
	c[1]=1;
	for(int i=1; i<=20; i++) //1.2的幂位置位变化
	{
		c[1<<i]=i+1;
	}
	for(int i=1; i<=2e+6; i++)
	{
		f[i]=fun(i);
		f[i]+=f[i-1];
	}
}

int main()
{
	memset(c,0,sizeof(c));
	memset(f,0,sizeof(f));
	init();
	cin>>t;
	while(t--)
	{
		int x,y;
		cin>>x>>y;//对x进行y次加1操作
		cout<<f[x+y]-f[x]<<endl;
	}
	return 0;
}
 4.keillempkill学姐の卷积

变化位置矩阵相乘。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int a[30][30],b[30][30],c[30][30];
int main()
{
	cin>>n>>m;
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n; j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=0; i<m; i++)
	{
		for(int j=0; j<m; j++)
		{
			cin>>b[i][j];
		}
	}
	for(int i1=0; i1<=m-n; i1++)
	{
		for(int i=0; i<=m-n; i++)
		{
			int temp=0;
			for(int j=0; j<n; j++)
			{
				for(int k=0; k<n; k++)
				{
					temp+=a[j][k]*b[i1+j][i+k];
				}	
			}
			cout<<temp<<" ";
		}
		cout<<endl;
	}
	return 0;
}
5.SSH

解题思路:由 ip地址 对应用户 私钥对应公钥(有多个公钥,对应唯一)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int m,n,q;
string pub,pri;//公钥,私钥
string ip;//ip地址
int k;//用户数量
string user;//用户名
unordered_map<string,string>pub_pri;//对应存储 公钥私钥
struct User//一个用户名可能多个公钥
{
	string username;//用户名
	unordered_set<string>publickeys;//公钥
} ;
unordered_map<string,unordered_map<string,User>>hosts;//对应存储 ip地址 用户 公钥
int main()
{
	cin>>m>>n>>q;
	while(m--)
	{
		cin>>pub>>pri;//公钥,私钥
		pub_pri[pri]=pub;//私钥唯一
	}
	while(n--)
	{
		cin>>ip>>k;//ip地址 用户数量
		while(k--)
		{
			int t;
			cin>>user>>t;
			User u;
			u.username=user;
			while(t--)//公钥数量
			{
				string pub1;
				cin>>pub1;
				u.publickeys.insert(pub1);//将公钥加入用户
			}
			hosts[ip][user]=u;//将用户信息存储(ip地址 用户名 公钥)
		}
	}
	while(q--)
	{
		cin>>user>>ip>>pri;//私钥
		if(hosts.count(ip)>0&&hosts[ip].count(user)>0) //ip地址和用户是否存在
		{
			User u=hosts[ip][user];
			if(pub_pri.count(pri)>0&&u.publickeys.count(pub_pri[pri])>0)//私钥存在 且hosts要有对应公钥
			{
				cout<<"Yes"<<endl;
			}
			else
			{
				cout<<"No"<<endl;
			}
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}
  • 16
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值