Codeforces Round #651 (Div. 2)

syx这场比赛打zbl,严重降智,觉得开始写cf题解

CF1370A Maximum GCD

显然如果n是偶数,那么取n,n/2,这时n/2是最大的gcd
如果n是奇数,那么取(n-1),(n-1)/2,这时(n-1)/2是最大的gcd

#include
using namespace std;
#define int long long
namespace Fread {
	const int MAXN=1<<20;
	char buf[MAXN],*S,*T;
	inline char getchar() {
		if (S==T) {
			T=(S=buf)+fread(buf,1,MAXN,stdin);
			if (S==T) return EOF;
		}
		return *S++;
	}
}
inline int read() {
	int x(0),neg(1);
	char ch=getchar();
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch-'0');
		ch=getchar();
	}
	return x*neg;
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
int n;
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int T=read();
	while(T--) {
		n=read();
		if (n%2==0) {
			printf("%lld\n",n/2);
		}
		else {
			printf("%lld\n",(n-1)/2);
		}
	}
	return 0;
}

CF1370B GCD Compression

显然可以贪
假设gcd为2,那么你只需要把奇数分一类,偶数分一类,取奇数和奇数一组,偶数和偶数一组

#include
using namespace std;
#define int long long
namespace Fread {
	const int MAXN=1<<20;
	char buf[MAXN],*S,*T;
	inline char getchar() {
		if (S==T) {
			T=(S=buf)+fread(buf,1,MAXN,stdin);
			if (S==T) return EOF;
		}
		return *S++;
	}
}
inline int read() {
	int x(0),neg(1);
	char ch=getchar();
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch-'0');
		ch=getchar();
	}
	return x*neg;
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
const int MAXN=10000ll;
int a[MAXN+5];
int c[MAXN+5];
int b[MAXN+5];
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int T=read();
	while(T--) {
		int n=read();
		int cnt1=0ll,cnt2=0ll;
		for (int i=1ll;i<=n*2ll;++i) {
			a[i]=read();
			if (a[i]%2ll==0ll) {
				b[++cnt1]=i;
			}
			else {
				c[++cnt2]=i;
			}
		}
		int cntt=0;
		for (int i=1;i<=cnt1-1;i+=2) {
			if (cntt

CF1370C Number Game

如果 \(n=1\)\(n=2^x\)\(n!=2\)\(n=2*一个质数\) 那么FastestFinger将获胜

  • 如果n是一个奇数,那么Ashishgup大可以直接除以n,则Ashishgup将获胜
  • 如果\(n=2^k\),那Ashishgup只能-1,FastestFinger只需直接除以\(n-1\)就行了
  • 如果n有奇数因子且是4的倍数,那么Ashishgup可以除以质数因子,然后FastestFinger只能-1,然后Ashishgup就可以除以当前的数使它变为1
  • 如果n是2*一个奇数
    如果奇数为质数,那么Ashishgup只能除以那个质数,然后FastestFinger对那个数-1就行
    如果奇数非质数,那么Ashishgup只需要除以其它所有质数,只剩下一个质因数,FastFinger便只能除以那个质因数,Ashishgup只需要再-1就赢了
    综上,代码如下:
#include
using namespace std;
#define int long long
namespace Fread {
	const int MAXN=1<<20;
	char buf[MAXN],*S,*T;
	inline char getchar() {
		if (S==T) {
			T=(S=buf)+fread(buf,1,MAXN,stdin);
			if (S==T) return EOF;
		}
		return *S++;
	}
}
inline int read() {
	int x(0),neg(1);
	char ch=getchar();
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch-'0');
		ch=getchar();
	}
	return x*neg;
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
int n;
int res;
inline void work() {
	if (res/n==2) {
		int awa=0;
		/*how many odd factors does it have*/
		for (int i=3;i<=sqrt(n);i+=2) {
			if (n%i==0) {
				++awa;
				break;
			}
		}
		if (awa>=1) {
			puts("Ashishgup");
		}
		else {
			puts("FastestFinger");
		}
	}
	else {
		puts("Ashishgup");
	}
}
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int T=read();
	while(T--) {
		n=read();
		if (n==1) {
			puts("FastestFinger");
		}
		else if (n==2) {
			puts("Ashishgup");
		}
		else if (n%2==0) {
			res=n;
			while(n%2==0) {
				n/=2;
			}
			if (n==1) {
				puts("FastestFinger");
				continue;
			}
			work();
		}
		else {
			puts("Ashishgup");
		}
	}
	return 0;
}

CF1370D Odd-Even Subsequence

一道较为简单的题,二分枚举答案+贪心选举

#include
using namespace std;
#define int long long
namespace Fread {
	const int MAXN=1<<20;
	char buf[MAXN],*S,*T;
	inline char getchar() {
		if (S==T) {
			T=(S=buf)+fread(buf,1,MAXN,stdin);
			if (S==T) return EOF;
		}
		return *S++;
	}
}
inline int read() {
	int x(0),neg(1);
	char ch=getchar();
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch-'0');
		ch=getchar();
	}
	return x*neg;
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
int cnt;
int n,k;
const int MAXN=200000;
vector c;
int a[MAXN+5];
int flag;
inline bool check(int x) {
	int cnt=0;
//	puts("awa");
	flag=0;
	/*solve as odd pos*/
	for (int i=1;i<=n;++i) {
		if (flag==1) {
			flag=0;
			cnt++; 
			continue;
		} 
		if (a[i]<=x) {
			flag=1;
			cnt++;
		}
	}
	if (cnt>=k) return 1;
//	puts("qwq");
	/*solve as even pos*/
	flag=0;
	cnt=1;
	for (int i=2;i<=n;++i) {
		if (flag==1) {
			flag=0;
			cnt++;
			continue;
		} 
		if (a[i]<=x) {
			flag=1;
			cnt++;
		}
	}
	if (cnt>=k) return 1;
	return 0; 
}
inline void Init() {
	cin>>n>>k;
	for (int i=1;i<=n;++i) {
		cin>>a[i];
	}
}
inline void erfen() {
	int l=1,r=1e9;
	while(l>1;
		if (check(mid)) {
			r=mid;
		}
		else {
			l=mid+1;
		}
	}
	printf("%lld\n",l);
}
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	Init();
	erfen();	
	return 0;
}

CF1370E Binary Subsequence Rotation

此题我是康CF题解的awa
如果\(s_i==t_i\),那么另\(a_i=0\)
否则,如果\(s_i==0\),那么另\(a_i=1\)
否则,另\(a_i=-1\)
先找最大值,再把1和-1反一下找最大值

  • 为什么这样是对的呢?
    形象理解一下,就是:如果在一段连续的序列里,1和-1可以抵掉(包含在同一subarray里),那么求Max就是答案
    代码:
#include
using namespace std;
//#define int long long
namespace Fread {
	const int MAXN=1<<20;
	char buf[MAXN],*S,*T;
	inline char getchar() {
		if (S==T) {
			T=(S=buf)+fread(buf,1,MAXN,stdin);
			if (S==T) return EOF;
		}
		return *S++;
	}
}
inline int read() {
	int x(0),neg(1);
	char ch=getchar();
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch-'0');
		ch=getchar();
	}
	return x*neg;
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
const int MAXN=1e6;
int n;
int a[MAXN+5];
int sum=0;
string s1,s2;
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(0); 
	cin.tie(0),cout.tie(0);
	cin>>n>>s1>>s2;
	for (int i=0;i

你可能感兴趣的:(Codeforces Round #651 (Div. 2))