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();
}
相关推荐
DoraBigHead28 分钟前
小哆啦解题记——两数失踪事件
前端·算法·面试
不太可爱的大白28 分钟前
Mysql分片:一致性哈希算法
数据库·mysql·算法·哈希算法
AI+程序员在路上34 分钟前
Qt6中模态与非模态对话框区别
开发语言·c++·qt
Tiandaren4 小时前
Selenium 4 教程:自动化 WebDriver 管理与 Cookie 提取 || 用于解决chromedriver版本不匹配问题
selenium·测试工具·算法·自动化
岁忧5 小时前
(LeetCode 面试经典 150 题 ) 11. 盛最多水的容器 (贪心+双指针)
java·c++·算法·leetcode·面试·go
chao_7896 小时前
二分查找篇——搜索旋转排序数组【LeetCode】两次二分查找
开发语言·数据结构·python·算法·leetcode
秋说7 小时前
【PTA数据结构 | C语言版】一元多项式求导
c语言·数据结构·算法
Maybyy8 小时前
力扣61.旋转链表
算法·leetcode·链表
卡卡卡卡罗特10 小时前
每日mysql
数据结构·算法
chao_78910 小时前
二分查找篇——搜索旋转排序数组【LeetCode】一次二分查找
数据结构·python·算法·leetcode·二分查找