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

题意:给数组an,然后定义数组的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();
}
相关推荐
青山木3 分钟前
Hot 100 --- 划分字母区间
java·数据结构·算法·leetcode·贪心算法
励志不掉头发的内向程序员17 分钟前
【LibreCAD 2D架构】鼠标点下的坐标为什么会被“吸”走?LibreCAD 对象捕捉系统解析
开发语言·c++·qt·学习·系统架构
Sunsets_Red20 分钟前
浅谈扫描线
c++·算法·编程·题解·洛谷·扫描线·信息学竞赛
a1879272183122 分钟前
【算法】双指针与滑动窗口(一):框架总纲——三类问题、一个原理与判决书
算法·leetcode·区间·双指针·滑动窗口·原理·算法讲解
shehuiyuelaiyuehao25 分钟前
算法42,模拟算法,模拟z字形变换
算法
朝朝辞暮i28 分钟前
C++第一课
开发语言·c++·算法
老赵的博客34 分钟前
c++ tcp的三次握手
c++
橘子汽水16835 分钟前
Leetcode 208,207实现Trie前缀树,课程表
java·数据结构·算法·leetcode
hanlin0340 分钟前
刷题笔记:力扣第169题-多数元素
笔记·算法·leetcode
张小姐的猫40 分钟前
【AI大模型接入SDK】 —— Ollama本地接入Deepseek
java·linux·开发语言·网络·c++·人工智能