20240821

赛时得分

题目 A B C D 总分 排名 比例
满分 100 100 100 100 400 171 100%
得分 100 40 30 0 170 57 33.3%

A. Phone(100/100)

来 NFLS 以后 CSP-S 模拟赛第一次做出 A 题。

\(\text{100%}\) 得分做法,由于答案按照字典序排序,并且需要去重,直接想到开一个 set<pair<string,string> > 解决。先存号码,再存名字,不合法的名字直接改回来即可。

#include<bits/stdc++.h>
#define Std_Maker lhm
#define ll long long
using namespace std;
ll n;
string str,num,tar;
set<pair<string,string> > s;
int main()
{
	freopen("phone.in","r",stdin);
	freopen("phone.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	while(n--)
	{
		cin>>str>>num;
		if(str[0]>='a' and str[0]<='z')
		{
			for(int i=0;i<str.length();i++) str[i]=str[i]-'a'+'A';
			s.insert({num,str});
		}
		else
		{
			if(str[1]>='a' and str[1]<='z')
			{
				tar="";
				for(int i=0;i<str.length();i++)
				{
					if(str[i]>='A' and str[i]<='Z') tar+=str[i];
				}
				s.insert({num,tar});
			}
			else s.insert({num,str});
		}
	}
	for(auto i:s) cout<<i.second<<" "<<i.first<<endl;
	return 0;
}

B. 知知的随机区间(40/100)

\(\text{40%}\) 得分做法,直接模拟整个操作,枚举所有的子段分别求异或、与、或和即可,得到的和值除以方案数就是期望。

#include<bits/stdc++.h>
#define Std_Maker lhm
#define ll long long
using namespace std;
const int N=1e5+1;
ll n,a[N];
double vx,vo,va;
ll getxor(ll l,ll r)
{
	if(l==r) return a[l];
	ll ans=a[l];
	for(int i=l+1;i<=r;i++) ans^=a[i];
	return ans;
}
ll getor(ll l,ll r)
{
	if(l==r) return a[l];
	ll ans=a[l];
	for(int i=l+1;i<=r;i++) ans|=a[i];
	return ans;
}
ll getand(ll l,ll r)
{
	if(l==r) return a[l];
	ll ans=a[l];
	for(int i=l+1;i<=r;i++) ans&=a[i];
	return ans;
}
int main()
{
	freopen("interval.in","r",stdin);
	freopen("interval.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			vx+=getxor(min(i,j),max(i,j));
			vo+=getor(min(i,j),max(i,j));
			va+=getand(min(i,j),max(i,j));
		}
	}
	printf("%.3lf %.3lf %.3lf",vx/n/n,va/n/n,vo/n/n);
	return 0;
}

C. 全民健身(30/100)

\(\text{30%}\) 得分做法,直接 dfs 构造一个乒乓球和排球的 0/1 序列,在写一个函数求第 \(i\) 行最近的乒乓球/排球所在行,直接模拟即可。

#include<bits/stdc++.h>
#define Std_Maker lhm
#define ll long long
using namespace std;
const int N=4001,inf=2147483647;
ll n,a[N],b[N],c[N];
set<ll> ans;
ll getnum(ll c[])
{
	ll ans=0;
	set<ll> check;
	check.clear();
	for(int i=1;i<=n;i++) check.insert(c[i]);
	if(check.size()==1) return inf;
	for(int i=1;i<=n;i++)
	{
		ll cnt=inf;
		if(c[i]==1)
		{
			for(ll j=i-1;j>=1;j--)
			{
				if(c[j]==0)
				{
					cnt=i-j;
					break;
				}
			}
			for(ll j=i+1;j<=n;j++)
			{
				if(c[j]==0)
				{
					cnt=min(j-i,cnt);
					break;
				}
			}
			if(cnt!=inf) ans+=a[i]*cnt;
		}
		else
		{
			for(ll j=i-1;j>=1;j--)
			{
				if(c[j]==1)
				{
					cnt=i-j;
					break;
				}
			}
			for(ll j=i+1;j<=n;j++)
			{
				if(c[j]==1)
				{
					cnt=min(j-i,cnt);
					break;
				}
			}
			if(cnt!=inf) ans+=b[i]*cnt;
		}
	}
	return ans;
}
void dfs(ll pos)
{
	if(pos>n+1) return;
	if(pos==n+1)
	{
		ans.insert(getnum(c));
		return;
	}
	c[pos]=0;
	dfs(pos+1);
	c[pos]=1;
	dfs(pos+1);
	return;
}
int main()
{
	freopen("gym.in","r",stdin);
	freopen("gym.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	c[1]=0,c[2]=1;
	dfs(1);
	cout<<*ans.begin();
	return 0;
}
posted @ 2024-08-21 14:18  Lithium_Chestnut  阅读(6)  评论(0)    收藏  举报