• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
magicat
博客园    首页    新随笔    联系   管理    订阅  订阅
2021四川省赛

The 2021 Sichuan Provincial Collegiate Programming Contest

A - Chuanpai

#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int k;	cin>>k;
	int ans=0;
	for(int i=1;i<=6;i++)
		for(int j=i;j<=6;j++)
			if(i+j==k)
				ans++;
	cout<<ans<<endl;
}

int main()
{
	int t;	
	cin>>t;
	while(t--)
		solve();
	return 0;

}

K - K-skip Permutation

#include<bits/stdc++.h>

using namespace std;


int n,k;
vector<int> ans;

set<int> s;
void solve()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		s.insert(i);
	while(s.size()>=1)
	{
		int t=*s.begin();
		while(s.count(t)==1)
		{
			ans.push_back(t);
			s.erase(t);
			t=t+k;
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<ans[i];
		if(i!=n-1)
			cout<<" ";
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);

	solve();
	return 0;

}

D - Rock Paper Scissors

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
LL a[4],b[4];
void solve()
{
	cin>>a[1]>>a[2]>>a[3];
	cin>>b[1]>>b[2]>>b[3];
	LL ans=0;

	LL t=min(a[1],b[2]);
	ans+=t,a[1]-=t,b[2]-=t;

	t=min(a[2],b[3]);
	ans+=t,a[2]-=t,b[3]-=t;

	t=min(a[3],b[1]);
	ans+=t,a[3]-=t,b[1]-=t;

	for(int i=1;i<=3;i++)
	{
		t=min(a[i],b[i]);
		a[i]-=t,b[i]-=t;
	}
	for(int i=1;i<=3;i++)
		ans-=a[i];

	cout<<ans<<endl;


}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);
	int t;	
	cin>>t;
	while(t--)
		solve();
	return 0;

}

M - True Story

#include<bits/stdc++.h>

using namespace std;


using LL = long long;

const int N = 1e5 + 10;

int n,k;
LL x,v[N],p[N],t[N];
bool cmp(LL t1,LL t2)
{
	return t1>t2;
}
/*
4 3 10 4 
1 5 2 1 
3 4 5
7 9 10

1 3 10 3 
1 
2 3 4
5 8 10
*/
void solve()
{
	cin>>n>>k>>x>>p[1];
	t[1] = 0;
	LL maxt=p[1];

	for(int i=1;i<=n;i++)
		cin>>v[i];
	for(int i=1;i<=k;i++)
		cin>>t[i];

	for(int i=1;i<=k;i++)
		cin>>p[i];

	for(int i=1;i<=k;i++)
		maxt=max(maxt,p[i]-t[i]);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		LL S=v[i]*maxt;
		if(S>=x)
			ans++;
	}


	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);

		solve();
	return 0;

}

H - Nihongo wa Muzukashii Desu

#include<bits/stdc++.h>

using namespace std;

string init[10][10];
string c[10];
int sz[10];
/*
10 
machimasu 
kaerimasu 
nomimasu 
yobimasu 
shinimasu 
kakimasu 
ikimasu 
kikimasu 
isogimasu
kashimasu
*/
void ini()
{
	init[1][1]="?imasu";
	init[1][2]="?chimasu";
	init[1][3]="?rimasu";
	c[1]="tte";


	init[2][1]="?mimasu";
	init[2][2]="?bimasu";
	init[2][3]="?nimasu";
	c[2]="nde";

	init[3][1]="?kimasu";
	c[3]="ite";

	init[4][1]="?gimasu";
	c[4]="ide";

	init[5][1]="?shimasu";
	c[5]="shite";

	sz[1]=sz[2]=3,sz[3]=sz[4]=sz[5]=1;
}
void solve()
{
	string s;	
	cin>>s;
	int len=s.size();
	if(s=="ikimasu")
	{
		cout<<"itte"<<endl;
		return;
	}
	s="?"+s;
	for(int i=1;i<=len;i++)
	{
		for(int j=1;j<=5;j++)
		{
			for(int k=1;k<=sz[j];k++)
			{
				if(len-i+1!=(int)init[j][k].size()-1)
					continue;
				string t="?";
				for(int q=i;q<=len;q++)
					t=t+s[q];
				if(t==init[j][k])
				{
					for(int q=1;q<i;q++)
						cout<<s[q];
					cout<<c[j];
					cout<<endl;
					return;
				}
			}
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);
	ini();
	int t;	
	cin>>t;
	while(t--)
		solve();
	return 0;

}

B - Hotpot

#include<bits/stdc++.h>
#define int unsigned long long

using namespace std;

constexpr int N = 100010;

map<int, int> mp;
int a[N];
int hpp[N];
vector<int> v[N];
void solve()
{
	int n, m, k;
	cin >> n >> k >> m;

	for (int i = 0; i < n; i++) hpp[i] = 0;
	for (int i = 1; i <= k; i++) v[i].clear();
	mp.clear();

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		v[a[i]].push_back(i);
	}

	int round = m / n;
	if (round > 0)
	{
		for (int i = 1; i <= k; i++)
		{
			if (v[i].size() % 2 == 1)
			{
				if (round % 2 == 1)
				{
					for (int j = 0; j < v[i].size(); j++)
					{
						if (j % 2 == 0)
						{
							hpp[v[i][j]] += round / 2;
						}
						else hpp[v[i][j]] += (round + 1) / 2;
					}
					mp[i] += 1;
				}
				else
				{
					for (int j = 0; j < v[i].size(); j++)
					{
						hpp[v[i][j]] += round / 2;
					}
				}
			}
			else
			{
				for (int j = 0; j < v[i].size(); j++)
				{
					if (j % 2 == 1)
					{
						hpp[v[i][j]] += round;
					}
				}
			}
		}
	}

	m %= n;
	int cur_round = 0;
	int now = 0;
	while (++cur_round <= m)
	{
		if (mp[a[now]] != 0)
		{
			hpp[now]++;
			mp[a[now]]=0;
		}
		else
		{
			mp[a[now]]++;
		}
		now = (now + 1) % n;
	}

	for (int i = 0; i < n; i++)
	{
		cout << hpp[i];
		if (i < n - 1) cout << ' ';
	}
	cout << '\n';
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);

	int T;
	cin >> T;

	while (T--) solve();

	return 0;

}

L - Spicy Restaurant

分析:直接bfs会TLE,但发现题意要求找到能满足辣度要求最近的点,代表辣度小于游客要去的点也可以,将辣度小的距离转移到辣度大的即可AC

#include<bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;

using PII = pair<int,int>;
int n,q,m;
vector<int> e[N],wi[110];
int dist[110][N];
bool vis[110][N];
int ans[110][N];
void dijkstra(int c)
{
	priority_queue<PII,vector<PII>,greater<PII>> q;
	
	for(int i=1;i<=n;i++)
		vis[c][i]=false;
	int len=wi[c].size();
	for(int i=0;i<len;i++)
	{
		int dot=wi[c][i];
		dist[c][dot] = 0;
		q.push({0,dot});
		//cout<<c<<" "<<dot<<endl;
	}
	while(q.size()>=1)
	{
		auto t = q.top(); q.pop();
		int u=t.second,cost=t.first;
		if(vis[c][u])	continue;
		vis[c][u]=true;
		for(auto v:e[u])
		{
			if(dist[c][v]>cost + 1)
			{
				dist[c][v]=cost+1;
				q.push({dist[c][v],v});
			}
		}
	}


}

void solve()
{
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
	{
		int w;	cin>>w;
		wi[w].push_back(i);
	}	
	for(int i=1;i<=m;i++)
	{
		int u,v;	cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);		
	}

	
	for(int c=1;c<=100;c++)
	{
		for(int i=1;i<=n;i++)
			dist[c][i]=1e9;
	}



	for(int c=1;c<=100;c++)
	{
		if(c!=1)	
			for(int i=1;i<=n;i++)
				dist[c][i]=min(dist[c][i],dist[c-1][i]);
		dijkstra(c);
	}

	while(q--)
	{
		int p,a;
		cin>>p>>a;
		if(dist[a][p]==1e9)
			cout<<-1<<endl;
		else cout<<dist[a][p]<<endl;
	}

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);
	solve();
	return 0;

}

E-Don't Really Like How The Story Ends

用一个队列去维护dfs序的过程

#include<bits/stdc++.h>

using namespace std;

#define PII  pair<int, int>
const int N = 1e5 + 10;
bool vis[N];
set<PII> s;
int n, m;
vector<int> e[N];
deque<int> q;
int ans;

void dfs(int u)
{
    vis[u] = true;
    while(q.size() >= 1 && q.front() <= u)
        q.pop_front();
    if(u == n)
        return;


    // 有边   for记录回溯的点
    if(s.count({u, u + 1}) == 1)
    {
    	int len = e[u].size();
        for(int i = len - 1;i >= 0; i--)
        {
        	int v = e[u][i];
            if(v == u + 1)  continue;
            q.push_front(v);
        }
        dfs(u + 1);
    }
    else if(s.count({u, u + 1}) == 0)
    {
        if(e[u].size() == 0 && q.size() >= 1 && q.front() == u + 1)
        {
            dfs(u + 1);
        }
        else 
        {
            ans++;
    		int len = e[u].size();
        	for(int i = len - 1;i >= 0; i--)
        	{
        		int v = e[u][i];
            	if(v == u + 1)  continue;
            	q.push_front(v);
        	}
            dfs(u + 1);
        }

    }
}
void solve()
{
    ans = 0;
	s.clear();
    while(q.size()>=1)  q.pop_front();
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        e[i].clear();
        vis[i] = false;
    }
    for(int i=1;i<=m;i++)
    {
    	int u,v;	cin>>u>>v;
    	if(u == v)	continue;
        if(u > v)
            swap(u, v);
    	e[u].push_back(v);
        s.insert({u, v});
    }
    for(int i=1;i<=n;i++)
        sort(e[i].begin(),e[i].end());
    dfs(1);
    cout<<ans<<endl;
	                                                                                         
}

int main()
{
	ios::sync_with_stdio(false);	cin.tie(nullptr);	cout.tie(nullptr);
	int t;	
	cin>>t;
	while(t--)
		solve();
	return 0;

}
/*
3 
2 3 
1 1 
1 2 
2 1

4 1 
1 4 

4 2 
1 2
3 4


1
4 4
1 2
1 3
1 4
2 3

1
6 2
4 6
3 5

1
5 6
1 2
1 4 
1 6
2 3
3 4
3 6

2
6 9
1 2
1 5
1 6
2 5
2 6
2 3
3 5
3 6
3 4
6 9
1 2
1 5
1 6
2 5
2 6
2 3
3 5
3 6
3 4

1
7 4
1 2
2 3
3 4
1 5

*/

本文来自博客园,作者:magicat,转载请注明原文链接:https://www.cnblogs.com/magicat/p/17429104.html

posted on 2023-05-24 17:51  magicat  阅读(90)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3