第33次CCF计算机软件能力认证C++代码

T1

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m;
bool pd[210][210];int temp;
long long ci[110],tot[1010];int t1;
int main()
{
	memset(ci,0,sizeof(ci));
	memset(tot,0,sizeof(tot));
	memset(pd,false,sizeof(pd));

	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&temp);
		for(int j=1;j<=temp;j++)
		{
			
			scanf("%d",&t1);
			if(pd[t1][i]==false)
			{
				pd[t1][i]=true;
				ci[t1]++;
			}
			tot[t1]++;
		}
	}
	for(int i=1;i<=m;i++)
	{
		printf("%d %d\n",ci[i],tot[i]);
	}
	return 0;
	
}

T2

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int n,m;
set<string> ans2;
set<string> a,b;
int t1;
int main()
{
	string t1;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		cin>>t1;
		int len=t1.length();
		for(int j=0;j<len;j++)
		{
			if(t1[j]<='Z'&&t1[j]>='A')
			{
				t1[j]=t1[j]-('A'-'a');
			}
		}
		a.insert(t1);
		ans2.insert(t1);
	//	cout<<t1<<" ";
	}
	for(int i=1;i<=m;i++)
	{
		cin>>t1;
		int len=t1.length();
		for(int j=0;j<len;j++)
		{
			if(t1[j]<='Z'&&t1[j]>='A')
			{
				t1[j]=t1[j]-('A'-'a');
			}
		}b.insert(t1);
		ans2.insert(t1);
		
	//	cout<<t1<<" ";
	}
	printf("%d\n%d",a.size()+b.size()-ans2.size(),ans2.size());
	return 0;
	
}

T3

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<cmath>
#define eps 1e-9
using namespace std;
int n,m;
string wuzhi[51];
set<string> newwz;
int totyuansu=0;
double x[1001];
double xishu[101][101];
bool digit(char a)
{
	return a>='0'&&a<='9';
}
int Gauss(int equ,int var)
{
	int n=equ;
	int curi=0;
	for(int j=0;j<var;j++)
	{
	/*	for(int we=0;we<=totyuansu;we++)
			{
				for(int z=0;z<=var;z++)
				{
					cout<<xishu[we][z]<<" ";
				}
				cout<<endl;
			}
			cout<<endl;*/
		int t;
		for(t=curi;t<equ;t++)
			if(fabs(xishu[t][j])>eps) break;
		if(t==equ) continue;
		for(int i=j;i<=var;i++)
		swap(xishu[t][i],xishu[curi][i]);
		for(int i=var;i>=j;i--)
		xishu[curi][i]/=xishu[curi][j];
		for(int i=0;i<equ;i++)
		if(i!=curi)
		for(int k=var;k>=j;k--)
			xishu[i][k]-=xishu[curi][k]*xishu[i][j];
		curi++;
		
		/*	for(int we=0;we<=totyuansu;we++)
			{
				for(int z=0;z<=var;z++)
				{
					cout<<xishu[we][z]<<" ";
				}
				cout<<endl;
			}
			cout<<endl;
		*/
	}
	int rank=0;
	bool pd1[10010];
	memset(pd1,false,sizeof(pd1));
	for(int i=0;i<equ;i++)
	{
		for(int j=0;j<var;j++)
		{
			if(xishu[i][j]!=0&&pd1[i]==false)
			{
				pd1[i]=true;
				rank++;
				
			}
		}
	}
	return rank<var;
	
	if(curi<equ)
	{
		for(int i=curi;i<equ;i++)
		if(fabs(xishu[i][var])>eps)
		{
			return 0;
		}
		return 1;
	}else
	{
	for(int i=0;i<equ;i++)
	printf("x%d=%.2lf\n",i+1,xishu[i][var]);	
	return 1;
}
	
 } 
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		map<string,int> duiying;
		map<int,string> fanduiying;
		newwz.clear();
		totyuansu=0;
		int p;
		scanf("%d",&p);duiying.clear();
		memset(xishu,0,sizeof(xishu));
		memset(x,0,sizeof(x));
		totyuansu=-1;
		for(int qw=1;qw<=p;qw++)
		{
			
			cin>>wuzhi[qw];
			int len=wuzhi[qw].length();
			int las=-1,temp=0;
			string yuansu;
			for(int i=0;i<=len;i++)
			{
				if(digit(wuzhi[qw][i]))
				{
					temp=temp*10+wuzhi[qw][i]-'0';
					continue;
				}
				else 
				{
					if(temp==0)
					{
						yuansu+=wuzhi[qw][i];
					//	cout<<"*"<<yuansu<<" "<<i<<endl;
					}
					else
					{
					//	cout<<"!"<<newwz.count(yuansu)<<endl;
						if(newwz.count(yuansu)==0)
						{
							++totyuansu;
							newwz.insert(yuansu);
							duiying[yuansu]=totyuansu;
							fanduiying[totyuansu]=yuansu;
						}
						
					//	cout<<duiying[yuansu]<<" "<<newwz.size()<<" "<<totyuansu<<endl;;
						int xishuwz=duiying[yuansu];
			//			int xishuwz=newwz.size();
						//xishu[xishuwz][0]++;
						xishu[xishuwz][qw-1]=temp;
					//	cout<<"!"<<yuansu<<" "<<temp<<" "<<xishuwz<<" "<<xishu[xishuwz][0]<<" "<<i<<endl;
						yuansu.clear();
						temp=0;
						yuansu+=wuzhi[qw][i];
					}
					
				}
				
			}
		
		
	
		}
				printf("%c\n",Gauss(totyuansu+1,p)?'Y':'N');
	/*	for(int j=0;j<=6;j++)
		cout<<x[j]<<" ";
		cout<<"\n";*/
			
		
		
		
		
		
		
		
		
		
	}
	return 0;
	
}

T4

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<cmath>
#include<queue>
#define eps 1e-9
using namespace std;
long long n,m,c;

long long totwa=0;
map<long long,int> num;
bool vis[1000000001];
struct node
{
	int wz,yd,tno;
}node[10000001];
struct fi
{
	int l,r;
}fin[300005];
map<int,int> ys;
bool cmp(struct node a,struct node b)
{
	return a.wz<b.wz;
}
void bao(long long t1)
{
	priority_queue<long long>q;
	if(num[t1]>=5)
	{
	vis[t1]=1;
	q.push(-t1);
	}
	while(!q.empty())
	{
	/*		for(int i=1;i<=m;i++)
	cout<<num[i]<<" ";
	cout<<endl;
	*/		long long x=q.top()*-1;
			q.pop();
			vis[x]=0;
			//cout<<x<<"!"<<endl;
			num[x]=0;
			totwa--;
			fin[fin[x].l].r=fin[x].r;
			fin[fin[x].r].l=fin[x].l;	
			int po=fin[x].l;
	
				if(num[po]>=1)
				{
					num[po]++;
				//	cout<<"lpo"<<po<<" "<<num[po]<<endl;
					if(num[po]>=5&&vis[po]==false)
					{
				//	cout<<"lpo"<<po<<" "<<num[po]<<endl;

					vis[po]=true;
					q.push(-po);
					}
				
				}
			po=fin[x].r;
			
				if(num[po]>=1)
				{
					num[po]++;
					if(num[po]>=5&&vis[po]==false)
					{
					
					q.push(-po);
					vis[po]=true;
					}
				
				}
			
	
	}
}
int main()
{
	scanf("%lld%lld%lld",&c,&m,&n);
	for(int i=1;i<=m;i++)
	{
		long long t1;int t2;
		scanf("%lld%d",&t1,&t2);
		
			node[i].wz=t1;
			node[i].yd=t2;
		if(t2>0)
		totwa++;
		/*num[t1]=t2;
		*/
	}
	sort(node+1,node+1+m,cmp);
	for(int i=1;i<=m;i++)
	{
		node[i].tno=i;
		num[node[i].tno]=node[i].yd;
		ys[node[i].wz]=node[i].tno;	
		fin[i].l=i-1;
		fin[i].r=i+1;
	}

	for(int i=1;i<=n;i++)
	{
		long long t1;
		scanf("%lld",&t1);
		t1=ys[t1];
	//	cout<<"!"<<t1<<endl;
		num[t1]++;
		if(num[t1]==1)
		{
			totwa++;
		}
		else
		{
		 bao(t1);
		
		}
		printf("%lld\n",totwa);
	}
	return 0;
	
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值