排序+暴力

 #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】的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #599 (Div. 2)

    久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...

  7. Codeforces Round #599 (Div. 2)的简单题题解

    难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...

  8. Codeforces Round #599 (Div. 2)D 边很多的只有0和1的MST

    题:https://codeforces.com/contest/1243/problem/D 分析:找全部可以用边权为0的点连起来的全部块 然后这些块之间相连肯定得通过边权为1的边进行连接 所以答案 ...

  9. Codeforces Round #599 (Div. 2) E. Sum Balance

    这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <ios ...

随机推荐

  1. Word 分栏页码,一个页面两个不同页码的设置

    1. 前言 在一些报纸.杂志中,我们可以见到各种各样的排版风格效果,其中有一种效果是一个页面设置了两栏,并且每栏下面都有不同的页码,那么,这种效果是如何实现的呢?这种页码在Word中默认页码样式中是没 ...

  2. 把cgrep mgrep集成到bashrc

    https://android.googlesource.com/platform/build/+/android-4.4.3_r1/envsetup.sh 在~/.bashrc里面增加: #Andr ...

  3. 【Python基础】01_Python中的变量

    1.定义和运算: 变量名 = 值 定义变量举例: # 定义一个变量 myCar = "比亚迪F0" # 输出一个变量 print(myCar) 变量之间的简单运算举例: price ...

  4. 2019杭电多校一 K. Function (数论)

    大意: 给定$n(n\le 10^{21})$, 求$\sum\limits_{i=1}^n gcd(\lfloor\sqrt[3]{i}\rfloor,i)\mod 998244353$ 首先立方根 ...

  5. SIFT算法研究

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://underthehood.blog.51cto.com/2531780/65835 ...

  6. numix Docky

    今天我们介绍这款主题适用于 Docky 启动器的 numix 主题,关于 Docky 大家已经应该很熟悉了,一款类似 Mac 底部软件停放的快捷启动码头.如图: 这款主题是 Docky 的主题,如果你 ...

  7. vue拦截

    ```javascript import Vue from 'vue' import App from './App.vue' import router from './router' import ...

  8. ASE —— 第二次结对作业

    目录 重现基线模型 基线模型原理 模型的优缺点 模型重现结果 提出改进 改进动机 新模型框架 评价合作伙伴 重现基线模型 基线模型原理 我们选用的的模型为DeepCS,接下来我将解释一下它的原理. 我 ...

  9. Eclipse安装windowsbuilder

    详见:https://www.cnblogs.com/plusplus/p/9864708.html https://www.cnblogs.com/lsy-blogs/p/7717036.html ...

  10. [Python] Codecombat攻略 远边的森林 Forest (1-40关)

    首页:https://cn.codecombat.com/play语言:Python 第二界面:远边的森林Forest(40关)时间:2-6小时内容:if/else.关系操作符.对象属性.处理输入网页 ...