Codeforces Round #735 (Div. 2) (A-D)

Posted TURNINING

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #735 (Div. 2) (A-D)相关的知识,希望对你有一定的参考价值。

传送门

A . 思路:对于一个很大的数,区间越大最小的数是越小的,他们的乘积也就越小,所以枚举相邻两个数就行了。

#include<bits/stdc++.h>
using namespace std;
 
#define lsn (u << 1)
#define rsn (u << 1 | 1)
#define mid (l + r >> 1)
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef pair<double, double> P;
 
const int MAXN = 1e5 + 10;
const int MAX_LEN = 1e5 + 10;
const int MAX_LOG_V = 22;
const ll INF = 1e17;
const int inf = 0x3f3f3f3f;
const int mod = 19650827;
const double eps = 1e-7;
const ull B = 100000007;

int n;
ll a[MAXN];

void solve() 
	scanf("%d", &n);
	ll ans = 0;
	for(int i = 1; i <= n; i++) 
		scanf("%lld", &a[i]); 
	
	for(int i = 1; i < n; i++) 
		ans = max(min(a[i],a[i+1])*max(a[i],a[i+1]), ans);
	
	printf("%lld\\n", ans);



int main() 
	//ios::sync_with_stdio(false);
	int t = 1; scanf("%d", &t);  
	while(t--)  
		solve();
	

B: 思路:枚举后100个就行了。。。。

#include<bits/stdc++.h>
using namespace std;
 
#define lsn (u << 1)
#define rsn (u << 1 | 1)
#define mid (l + r >> 1)
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef pair<double, double> P;
 
const int MAXN = 1e5 + 10;
const int MAX_LEN = 1e5 + 10;
const int MAX_LOG_V = 22;
const ll INF = 1e17;
const int inf = 0x3f3f3f3f;
const int mod = 19650827;
const double eps = 1e-7;
const ull B = 100000007; 
 
 
int n, k;
int a[MAXN];
 
void solve() 
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	ll ans = -1e17;
	for(int i = max(1, n-1000); i <= n; i++) 
		for(int j = i+1; j <= n; j++) 
			ans = max(ans, (ll)i*j-(ll)k*(a[i]|a[j]));
		
	
	printf("%lld\\n", ans);

 
 
int main() 
	//ios::sync_with_stdio(false);
	int t = 1; scanf("%d", &t);
	while(t--) 
		solve();
	
	return 0;

C 思路:观察发现 n > m n > m n>m时 0 取不到,直接输出0。当 n < = m n <= m n<=m时 令 n ⨁ x = y n \\bigoplus x = y nx=y,根据题目要求,我们要找到一个y使 x > m x > m x>m且 y 最小。 n ⨁ y > m n \\bigoplus y > m ny>m , y ⨁ \\bigoplus n >= m + 1,怎么找最小的y呢,我们知道在二进制位中一个 2 i > ∑ j = 0 i − 1 2 j 2^i > \\sum_j=0^i-1 2^j 2i>j=0i12j, 故只有当二进制位上n为0,m为1时我们才让y取1。

#include<bits/stdc++.h>
using namespace std;
 
#define lsn (u << 1)
#define rsn (u << 1 | 1)
#define mid (l + r >> 1)
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef pair<double, double> P;
 
const int MAXN = 1e5 + 10;
const int MAX_LEN = 1e5 + 10;
const int MAX_LOG_V = 22;
const ll INF = 1e17;
const int inf = 0x3f3f3f3f;
const int mod = 19650827;
const double eps = 1e-7;
const ull B = 100000007; 


int n, m;


void solve() 
	scanf("%d %d", &n, &m);
	if(n > m) puts("0"); return ;
	m++;
	int res = 0;
	for(int i = 30; i >= 0; i--) 
		if(!(n >> i & 1) && (m >> i & 1)) res |= (1 << i);
		else if((n >> i & 1) && !(m >> i & 1)) break;
	
	printf("%d\\n", res);



int main() 
	//ios::sync_with_stdio(false);
	int t = 1; scanf("%d", &t);
	while(t--) 
		solve();
	
	return 0;

D 思路:研究一下样例发现,一连串含相同字符的字符串 ( 如 a a a a a ) (如aaaaa) (aaaaa)当再往后添加一个相同字符时,添加后相同长度的子串的个数为添加前的+1,一奇一偶相加肯定为奇数。特判一下n为1的情况

#include<bits/stdc++.h>
using namespace std;
 
#define lsn (u << 1)
#define rsn (u << 1 | 1)
#define mid (l + r >> 1)
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef pair<double, double> P;
 
const int MAXN = 1e5 + 10;
const int MAX_LEN = 1e5 + 10;
const int MAX_LOG_V = 22;
const ll INF = 1e17;
const int inf = 0x3f3f3f3f;
const int mod = 19650827;
const double eps = 1e-7;
const ull B = 100000007; 


int n;


void solve() 
	scanf("%d", &n);
	if(n == 1) puts("a"); return ;
	if(n % 2 == 0) 
		int t = n / 2;
		for(int i = 1; i < t; i++) printf("a");
		printf("b");
		for(int i = 1; i <= t; i++) printf("a");
	
	else 
		int t = n / 2;
		for(int i = 1; i < t; i++) printf("a");
		printf("bc");
		for(int i = 1; i <= t; i++) printf("a");
	
	puts("");



int main() 
	//ios::sync_with_stdio(false);
	int t = 1; scanf("%d", &t);
	while(t--) 
		solve();
	
	return 0;

以上是关于Codeforces Round #735 (Div. 2) (A-D)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #735 (Div. 2)-C. Mikasa-题解

Codeforces Round #735 (Div. 2)-B. Cobb-题解

Codeforces Round #735 (Div. 2)-A. Cherry-题解

Codeforces Round #735 (Div. 2)-C. Mikasa-题解

Codeforces Round #735 (Div. 2)-B. Cobb-题解

Codeforces Round #735 (Div. 2)-A. Cherry-题解