排序+暴力

 #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. GBK字符集

    GBK字库 编辑 同义词 GBK一般指GBK字库 GBK全称<汉字内码扩展规范>(GBK即“国标”.“扩展”汉语拼音的第一个字母,英文名称:Chinese Internal Code Sp ...

  2. python第一个浏览器的自动执行程序

    1.目标:简单点,百度搜索“美丽的程序员” 2.操作方法: a.python已经安装完成 b.安装PIP:在windows的cmd窗口下输入easy_install pip      c.安装sele ...

  3. Linux (x86) Exploit 开发系列教程之二(整数溢出)

    (1)漏洞代码 //vuln.c #include <stdio.h> #include <string.h> #include <stdlib.h> void s ...

  4. PHP trait介绍

    Trait 自 PHP 5.4.0 起,PHP 实现了一种代码复用的方法,称为 trait. Trait 是为类似 PHP 的单继承语言而准备的一种代码复用机制.Trait 为了减少单继承语言的限制, ...

  5. C#xml泛型序列化

    using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Web ...

  6. MarkDown 语法记录

    Markdown是一种纯文本格式的标记语言.通过简单的标记语法,它可以使普通文本内容具有一定的格式. 为啥要用 MarkDown 呢? 优点 1.因为是纯文本,所以只要支持Markdown的地方都能获 ...

  7. vue使用layer主动关闭弹窗

    关闭当前框的弹出层 layer.close(layer.index); 刷新父层 parent.location.reload(); // 父页面刷新 关闭iframe 弹出的全屏层 var inde ...

  8. ORACLE 存储过程提高

    1.SQLCODE和SQLERRM 2.%TYPE和%ROWTYPE的使用 3.sql%rowcount的作用 1.SQLCODE和SQLERRM SQLCode:数据库操作的返回码,其中 --成功: ...

  9. 前阿里P8架构师谈如何设计优秀的API

    随着大数据.公共平台等互联网技术的日益成熟,API接口的重要性日益凸显,从公司的角度来看,API可以算作是公司一笔巨大的资产,公共API可以捕获用户.为公司做出许多贡献.对于个人来说,只要你编程,你就 ...

  10. 配置Python、Django环境变量教程

    配置环境变量 在Windows下你必须配置环境变量! 右击桌面或者你能看到的任何 此电脑.这台电脑或者我的电脑. 右击:属性 点击:高级系统设置 点击:环境变量 找到系统变量下的Path,双击 点击新 ...