Codeforces Round #599 (Div. 2) A,B1,B2,C 【待补 D】

排序+暴力
#include<bits/stdc++.h> using namespace std; #define int long long
#define N 1005000
int arr[N]; signed main(){
int _,n;
cin>>_;
while(_--){
cin>>n;
for(int i=;i<=n;i++)
cin>>arr[i];
sort(arr+,arr++n);
int ans=;
for(int i=;i<=n;i++){
int flag=;
int s=;
for(int j=n;j>=;j--){
if(arr[j]>=i)
s++;
if(s>=i){
flag=;
break;
}
}
if(flag){
ans=i;
}else{
break;
}
}
cout<<ans<<'\n';
}
return ;
}

直接暴力就行。【数据范围看错了。少开了一个0。啊啊,难受QAQ。。。。。。。】
#include<bits/stdc++.h> using namespace std; #define int long long
#define N 1500
int a[N];
signed main(){
int _;
cin>>_;
while(_--){
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
if(s1==s2){
printf("Yes\n");
continue;
}
int flag=;int s=; memset(a,,sizeof(a));
int cnt=;
for(int i=;i<s1.size();i++){
if(s1[i]!=s2[i]){
a[cnt++]=i;
s++;
}
if(s>){
break;
}
}
if(s!=){
printf("No\n");
}else{
if((s1[a[]]==s1[a[]]&&s2[a[]]==s2[a[]])){
printf("Yes\n");
}else{
printf("No\n");
}
}
}
return ;
}

思路:当字符串不相等时,优先考虑同行。当同行没有字符串时再考虑另外一行。模拟即可。
#include<bits/stdc++.h> using namespace std;
#define int long long signed main(){
int _;
cin>>_;
while(_--){
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
int sum=;int X=;
vector<pair<int,int> > ans;
for(int i=;i<n;i++){
if(s1[i]!=s2[i]){
int flag1=;int flag2=;
for(int j=i+;j<n;j++){
if(s1[j]==s1[i]){
flag1=;
sum++;
ans.push_back(make_pair(j+,i+));
swap(s1[j],s2[i]);
break;
}
}
if(!flag1){
for(int j=i+;j<s2.size();j++){
if(s2[j]==s1[i]){
sum+=;
flag2=;
ans.push_back(make_pair(j+,j+));
ans.push_back(make_pair(j+,+i));
swap(s2[j],s1[j]);
swap(s1[j],s2[i]);
break;
}
}
}
if(flag1==&&flag2==){
X=;
break;
}
}
}
if(X){
printf("No\n");
continue;
}
if(sum<=*n){
printf("Yes\n");
printf("%lld\n",sum);
for(int i=;i<ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second<<'\n';
}
}else{
printf("No\n");
}
}
return ;
}

题意:给排成一行的 n个格子,要求所有的 i,j 满足 |i−j|是 n 的因子的,都要同色,求最大的涂色数。
思路:所有因子的GCD。
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;cin>>n;
int ans=;
int flag=;
int K=;
for(int i=;i*i<=n;i++){
if(n%i==){
flag=;
if(!K){
ans=i;
ans=__gcd(ans,n/i);
K=;
}else{
ans=__gcd(ans,i);
ans=__gcd(ans,n/i);
}
}
}
if(flag==){
cout<<n<<'\n';
return ;
}
cout<<ans;
return ;
}
菜是原罪。
Codeforces Round #599 (Div. 2) A,B1,B2,C 【待补 D】的更多相关文章
- Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)
Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造
B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...
- Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version) 水题
B1. Character Swap (Easy Version) This problem is different from the hard version. In this version U ...
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version)
This problem is different from the easy version. In this version Ujan makes at most 2n2n swaps. In a ...
- Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version)
This problem is different from the hard version. In this version Ujan makes exactly one exchange. Yo ...
- Codeforces Round #599 (Div. 2)
久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...
- Codeforces Round #599 (Div. 2)的简单题题解
难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...
- Codeforces Round #599 (Div. 2)D 边很多的只有0和1的MST
题:https://codeforces.com/contest/1243/problem/D 分析:找全部可以用边权为0的点连起来的全部块 然后这些块之间相连肯定得通过边权为1的边进行连接 所以答案 ...
- Codeforces Round #599 (Div. 2) E. Sum Balance
这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <ios ...
随机推荐
- golang字符串常用的系统函数
1.统计字符串的长度,按字节len(str) str := "hello北京" fmt.Println("str len=", len(str)) 2.字符串遍 ...
- 安装jar包到本地仓库
1.控制台安装 安装指定文件到本地仓库命令:mvn install:install-file-DgroupId=<groupId> : 设置项目代码的包名(一般用组织名)-Da ...
- asp.net core-2.在vs2017中创建asp.net core应用程序
今天我们用vs2017创建一个asp.net core 的应用程序,打开vs2017 点击:文件—>项目,选择asp.net core web 应用程序 点击确定 红框内就昨天用控制台去创建的应 ...
- shell脚本使用记录
一些比较功能需求比较简单的可以考虑使用shell脚本来写,这样可以方便快捷稳定 1. 读取文件值,根据文件值1 或 0 来开启和关闭某些程序 a. while : do done 是无限循环. b. ...
- Spring的SSM标准配置
一.首先是web.xml文件的配置 <welcome-file-list> <!--设置默认显示登陆界面--> <welcome-file>login.jsp< ...
- kong网关命令(一)
上次在虚拟机里安装kong网关后,因为版本(1.4)太高,目前Kong Dashboard无法支持, 后续发现Git上有个开源工具Kong admin ui,下载源码并部署到NGINX. 但是发现使用 ...
- Shell学习笔记:awk实现group by分组统计功能
日常部分数据以 txt 的文件格式提供,为避免入库之后再进行统计的麻烦,故学习 shell 进行处理,减少工作量. 1.样例数据 # test.txt YD5Gxxx|6618151|68254490 ...
- 微信小程序tabBar与redirectTo 或navigateTo冲突
微信小程序tabBar与redirectTo 或navigateTo冲突 tabBar设置的pagePath无法再次被redirectTo或navigateTo引用 导致跳转失败,更改为swithTa ...
- git remote 使用总结
使用场景:新建一个git仓储并与远程关联 1.初始化一个新的空的git仓储,并在仓储下做一些改动 mkdir gitDir cd gitDir/ git init touch file git sta ...
- MVC方式显示数据(手动添加数据)
Model添加类 Customers using System; using System.Collections.Generic; using System.Linq; using System.W ...