Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) ABCD解题报告

Posted 桂月二四

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) ABCD解题报告相关的知识,希望对你有一定的参考价值。

A. Windblume Ode

A. Windblume Ode

题意:给定一个a数组,从中挑出尽可能多的数,使得这些数相加是合数。

解析:若a1+a2+…+an 为合数,则输出整个a数组,否则遍历1-n,删去其中的一个数,若剩下的数字为合数,则直接输出。可以证明答案个数一定>=n-1

#include <bits/stdc++.h>
#include<ext/rope>
#define pb push_back
#define debug(x) cerr<<#x<<'='<<x<<'\\n'
#define debugg(x,y) cerr<<#x<<'='<<x<<','<<#y<<'='<<y<<'\\n' 
#define FOR(a,b,c) for(int a=(b),a##_end=(c);a<=a##_end;++a)
#define ROF(a,b,c) for(int a=(b),a##_end=(c);a>=a##_end;--a)
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 200010 ,M = 1000010,mod = 998244353;
ll qmi(ll,ll);
template<typename T>inline bool chkmin(T &x,const T &y){return y<x?x=y,1:0;}
template<typename T>inline bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}
int n,m,d;
int a[N];
bool isp(ll x)
{
	if(x<=2) return x==2;
	int s = sqrt(x);
	for(int i=2;i<=s;i++)
		if(x%i==0)
			return 0;
	return 1;
	
}
signed main()
{
	int cas;read(cas);
	while(cas--)
	{
		read(n);
		ll sum  = 0;
		for(int i=1;i<=n;i++) read(a[i]),sum+=a[i];
		if(!isp(sum))
		{
			cout<<n<<'\\n';
			for(int i=1;i<=n;i++)
				cout<<i<<' ';
			puts("");
		}
		else
		{
			cout<<n-1<<'\\n';
			for(int i=1;i<=n;i++)
			{
				if(!isp(sum-a[i]))
				{
					for(int j=1;j<=n;j++)
						if(j!=i)
							cout<<j<<' ';
					
					break;
				}
			}
			puts("");
		}
	}    
    return 0;
}

ll qmi(ll a,ll b) {ll res=1;a%=mod;  for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}





B. Omkar and Heavenly Tree

题意:构造一颗有n个节点的树,并且满足q个询问,每个询问给出了 a,b,c 代表a到c的简单路径中不能包含b。

解析:由于m<n 所以b必然不会包括所有的节点,随机找到一个节点(不是b) 然后其他节点都连向该节点即可

#include <bits/stdc++.h>
#include<ext/rope>
#define pb push_back
#define debug(x) cerr<<#x<<'='<<x<<'\\n'
#define debugg(x,y) cerr<<#x<<'='<<x<<','<<#y<<'='<<y<<'\\n' 
#define FOR(a,b,c) for(int a=(b),a##_end=(c);a<=a##_end;++a)
#define ROF(a,b,c) for(int a=(b),a##_end=(c);a>=a##_end;--a)
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 200010 ,M = 1000010,mod = 998244353;
ll qmi(ll,ll);
template<typename T>inline bool chkmin(T &x,const T &y){return y<x?x=y,1:0;}
template<typename T>inline bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}
int n,m,d;
int a[N],b[N],c[N];
int ans[N],mp[N],vis[N];
signed main()
{
	int cas;read(cas);
	while(cas--)
	{
		read(n);read(m);
		for(int i=1;i<=n;i++) ans[i] = i,mp[i] =vis[i]= 0;
		for(int i=1;i<=m;i++) {
			read(a[i]),read(b[i]),read(c[i]);
			mp[b[i]] = 1;
		}
		int pos;
		for(int i=1;i<=n;i++)
		{
			if(!mp[i])
			{
				pos = i;
				break;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i!=pos)
				printf("%d %d\\n",pos,i);
		}
		
	}    
    return 0;
}

ll qmi(ll a,ll b) {ll res=1;a%=mod;  for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

C. Omkar and Determination

题意:给定一个nm的网格,格子上是X代表该网格是满的,格子上是.代表该格子是空的。 倘若从能从一个格子向左或者向上走,再仅仅通过空格子的情况下(不为’X’),能走出边界,则称该格子是合适的(E),否则为(N)。 给定m组询问,每组询问包含两个整数x1,x2,代表仅取x1-x2列的网格,给出这些列格子的合适情况(每个格子是E或N),问能否仅通过合适情况推出这些格子是满的还是空的(‘X’或’.’)

解析:当且仅当出现下列情况时,满与空无法判断

?X?
X??
???

即X出现在对角线上连续出现,若仅仅知道合适与不合适的情况,上图的第二列是无法完全推出的。(第二行第二列可以是X也可以是.)
因此,只要给定的x1-x2列之间没有这种情况,即为YES,用前缀和可以轻松解决

#include <bits/stdc++.h>
#include<ext/rope>
#define pb push_back
#define debug(x) cerr<<#x<<'='<<x<<'\\n'
#define debugg(x,y) cerr<<#x<<'='<<x<<','<<#y<<'='<<y<<'\\n' 
#define FOR(a,b,c) for(int a=(b),a##_end=(c);a<=a##_end;++a)
#define ROF(a,b,c) for(int a=(b),a##_end=(c);a>=a##_end;--a)
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 1000010 ,M = 1000010,mod = 998244353;
ll qmi(ll,ll);
template<typename T>inline bool chkmin(T &x,const T &y){return y<x?x=y,1:0;}
template<typename T>inline bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}
int n,m,d;
int a[N];
string s[N]; 
signed main()
{
	int cas=1;;
	while(cas--)
	{
		read(n),read(m);	
		vector<int> sum(m);
		for(int i=0;i<n;i++)
			cin>>s[i];
		for(int i=0;i<n-1;i++)
			for(int j=0;j<m-1;j++)
			{
				if(s[i+1][j]=='X'&&s[i][j+1]=='X')
					sum[j+1]++;
			}
		for(int i=1;i<m;i++) sum[i] += sum[i-1];
		int q;cin>>q;
		while(q--)
		{
			int a,b;read(a),read(b);
			--a,--b;
			puts(sum[a]==sum[b]?"YES":"NO");
		}
	}    
    return 0;
}

ll qmi(ll a,ll b) {ll res=1;a%=mod;  for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}





D. Omkar and the Meaning of Life

交互题:给定一个n,让我们通过<=2n次询问,让我们猜出题目中的排列p。 每次询问给出一个长度为n的a数组,交互系统会自动算出一个s数组,si = pi+ai ,然后返回一个下标k(下标k代表s数组中出现两次或以上的数字的最小下标)

解析:我们先通过n-1次询问计算出排列p中p[n]的值。首先假设p[n] = 1,由于a数组>=1,所以在这n-1次询问中将an调为1。在第i次询问中,a的其他值调为i+1;
正是下面这个意思:

ans[n] = 1;
FOR(i,2,n)
		{
			printf("? ");
			for(int j=1;j<n;j++)
				printf("%d ",以上是关于Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) ABCD解题报告的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #388 (Div. 2) 749E(巧妙的概率dp思想)

Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) ABCD解题报告

Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) ABCD解题报告

Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) ABCD解题报告

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)