Codeforces Round 952 (Div. 4)(实时更新)

A - Creating Words

题意:略

代码:

cpp 复制代码
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)//不能使用scanf了
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
const int N=1010;

using namespace std;
void solve() {
    string a,b;cin>>a>>b;
    char c=a[0];
    a[0]=b[0];
    b[0]=c;
    cout<<a<<' '<<b<<endl;
}
signed main() {
	ios;
	int n=1;
	cin >> n;
	while (n--)solve();
}

B - Maximum Multiple Sum

题意:略

代码:

cpp 复制代码
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
#define N 1e6+10
using namespace std;
void solve() {
    int n;cin>>n;
    auto check=[&](int t){
        int i=2;
        for(;i<=sqrt(t);i++)
            if(t%i==0)break;
        if(i>=sqrt(t))return 1;
        else return 0;
    };
    if(n<4)cout<<n<<endl;
    else cout<<2<<endl;
}
signed main() {
	ios;
	int n=1;
	cin >> n;
	while (n--)solve();
}

C - Good Prefixes

题意:给数组a[n],然后定义数组的2*max=sum,则认为这个数组是好数组

我们求sum和max,然后比较即可,可以用递推优化

代码:

cpp 复制代码
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
#define N 1e6+10
using namespace std;
void solve() {
	int n;	cin>>n;
	int a[n]; loop(n)cin>>a[i];
	int S[n],Max[n];
	loop(n){
		if(i==0)S[i]=a[i],Max[i]=a[i];
		else S[i]=S[i-1]+a[i],Max[i]=max(Max[i-1],a[i]);
	}
	int count=0;
	loop(n)
		if(S[i]==2*Max[i])count++;
	cout<<count<<endl;
}
signed main() {
	ios;
	int n=1;
	cin >> n;
	while (n--)solve();
}

D - Manhattan Circle

题意:找圆的圆心

代码:

cpp 复制代码
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
#define N 1e6+10
using namespace std;
void solve() {
	int n,m;cin>>n>>m;
	char a[n][m];
	int line=n-1,num=0,first=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	for(int i=0,count=0,k=0;i<n;i++,count=0){
		for(int j=0;j<m;j++){
			if(a[i][j]=='#')count++;
		}
		if(count==2*k+1)k++;
		else if(k!=0){
			line=i-1,num=count==0?1:count+2;
			break;
		}
		//如果在最后一行,line不会赋值,则line的初始值设为n-1
	}
	loop(m)if(a[line][i]=='#'){
		first=i;break;
	}
	cout<<line+1<<' '<<first+num/2+1<<endl;
}
signed main() {
	ios;
	int n=1;
	cin >> n;
	while (n--)solve();
}
相关推荐
老四啊laosi1 天前
[C++进阶] 24. 哈希表封装unordered_map && unordered_set
c++·哈希表·封装·unordered_map·unordered_set
2301_764441331 天前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
东北洗浴王子讲AI1 天前
GPT-5.4辅助算法设计与优化:从理论到实践的系统方法
人工智能·gpt·算法·chatgpt
妙为1 天前
银河麒麟V4下编译Qt5.12.12源码
c++·qt·国产化·osg3.6.5·osgearth3.2·银河麒麟v4
Billlly1 天前
ABC 453 个人题解
算法·题解·atcoder
玉树临风ives1 天前
atcoder ABC 452 题解
数据结构·算法
feifeigo1231 天前
基于马尔可夫随机场模型的SAR图像变化检测源码实现
算法
fengfuyao9851 天前
基于STM32的4轴步进电机加减速控制工程源码(梯形加减速算法)
网络·stm32·算法
无敌昊哥战神1 天前
深入理解 C 语言:巧妙利用“0地址”手写 offsetof 宏与内存对齐机制
c语言·数据结构·算法
小白菜又菜1 天前
Leetcode 2075. Decode the Slanted Ciphertext
算法·leetcode·职场和发展