首页 > 其他分享 >2021四川省赛

2021四川省赛

时间:2023-05-24 17:55:41浏览次数:51  
标签:10 四川省 int void solve 2021 ans using

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

*/

标签:10,四川省,int,void,solve,2021,ans,using
From: https://www.cnblogs.com/magicat/p/17429104.html

相关文章

  • 2022年第十四届四川省大学生程序设计大赛 A
    AAdjacentSwapping题意:给定一个字符串,每次可以移动相邻字符,求最小移动次数可以把它变成s+s这样左右两边相同的字符串。思路:1:我们知道他一定是偶数长度,所以我们把字符串分成两部分s1和s22:贪心的扫描一遍这个字符串,s1就是前一半,然后计算在满足这一般的时候他要移动多少次,即直......
  • HEUCPC2021
    stralReflection在\([1,n]\)上支持如下操作:操作一:学习一个新的技能——清除\([l,r]\)内所有的陨石操作二:给定一个点集\(k\)代表陨石出现在这些位置,询问最少需要使用多少技能才能清除所有陨石(不能使用当前没有学习的技能)共操作\(m\)次\(\sumk\leq1e5\)\(m\leq1e5\)......
  • 科技云报道荣膺全球云计算大会“云鼎奖”2020-2021年度优秀团队
    2021年6月16日-18日,第九届全球云计算大会·中国站(CloudConnectChina)在宁波隆重举行。本次大会上,科技云报道荣膺全球云计算大会“云鼎奖”2020-2021年度优秀团队奖项。科技云报道团队代表上台领奖(左一)科技云报道荣膺“云鼎奖”2020-2021年度优秀团队作为每年全球云计算大会·中国......
  • Audition 2021 for Mac软件安装包下载Au 2021软件安装教程
    [名称]:Audition2021[大小]:473MB[语言]:简体中文 [安装环境]:MacOS10.14及以上[是否支持M系列芯片]:支持[简介]:Audition是一种完善工具集,其中包括用于对音频内容进行创建、混音和编辑的多音轨、波形和光谱显示。这一强大的音频工作站旨在加快视频制作工作流程和音频修整的速度,并且......
  • ID2021Mac软件安装教程Indesign 2021 for Mac软件安装包下载
    [名称]:InDesign2021[大小]:1.29GB[语言]:简体中文 [安装环境]:MacOS10.14及以上[是否支持M系列芯片]:支持[简介]:InDesign是一个定位于专业排版领域的设计软件。借助这款业界领先的页面设计和版面应用程序,可以制作、印前检查和发布用于印刷和数字媒体出版的精美文档。InDesign拥有制......
  • June 2021-Continuous Transition: Improving Sample Efficiency for Continuous Cont
    摘要:尽管深度强化学习(RL)已成功应用于各种机器人控制任务,但由于样本效率较差,将其应用于现实世界任务仍然具有挑战性。为了克服这一缺点,一些工作侧重于在训练过程中重用收集的轨迹数据,将其分解为一组策略无关的离散变迁。然而,它们的改进有些边际,因为i)转换的数量通常很小,ii)值分......
  • CSP-J2021试题题解
    1.分糖果原题:https://www.luogu.com.cn/problem/P7909原代码:#include<bits/stdc++.h>#definelllonglongusingnamespacestd;lln,l,r;intmain(){ cin>>n>>l>>r; if(r%n==n-1)cout<<n-1; elseif(l%n==n-1)cout<<n-1; elseif(......
  • 从零玩转Activiti7工作流-2021-09-12-16-22-07
    title:从零玩转Activiti7工作流date:2021-09-1216:22:08.51updated:2021-12-2617:43:12.171url:https://www.yby6.com/archives/2021-09-12-16-22-07categories:-工作流tags:Activiti讲师:波波​工作流(Workflow),就是通过计算机对业务流程自动化执行......
  • Apache Log4j2远程代码执行漏洞(CVE-2021-44228)修复
    1、演示说明:最近在项目中遇到用户扫描es时发现ApacheLog4j2远程代码执行漏洞(CVE-2021-44228),该漏洞具体原理不再赘述,此处分享解决过程。2、演示环境:(1)系统版本:#cat/etc/redhat-release(2)JDK版本:#java-version(3)es版本:#./elasticsearch-V3、下载命令行扫描工具:下载地址:https://gi......
  • Spring Cloud开发实践(六): 基于Consul和Spring Cloud 2021.0的演示项目
    目录SpringCloud开发实践(一):简介和根模块SpringCloud开发实践(二):Eureka服务和接口定义SpringCloud开发实践(三):接口实现和下游调用SpringCloud开发实践(四):Docker部署SpringCloud开发实践(五):Consul-服务注册的另一个选择SpringCloud开发实践(六):基......