Codeforces_798
A.暴力把每个位置的字符改成另外25个字符,判断是否回文。
#include<bits/stdc++.h>
using namespace std; string s; int main()
{
ios::sync_with_stdio(false);
cin >> s;
for(int i = ;i < s.length();i++)
{
for(char j = 'a';j <= 'z';j++)
{
if(s[i] == j) continue;
string ss = s;
ss[i] = j;
string sss = ss;
reverse(sss.begin(),sss.end());
if(sss == ss)
{
cout << "YES" << endl;
return ;
}
}
}
cout << "NO" << endl;
return ;
}
B.先判断是否都能变成相同串,若可以,则有一个特点,最后的串肯定与初始某个串相同,直接暴力就可以了。
#include<bits/stdc++.h>
using namespace std; int n,a[][];
string s[];
map<string,int> mp; int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = ;i <= n;i++) cin >> s[i];
int cnt = ;
for(int i = ;i < s[].length();i++)
{
string ss = s[].substr(i)+s[].substr(,i);
mp[ss] = ;
}
for(int i = ;i <= n;i++)
{
if(s[i].length() != s[].length() || !mp.count(s[i]))
{
cout << - << endl;
return ;
}
}
int ans =1e9;
for(int i = ;i <= n;i++)
{
int sum = ;
for(int j = ;j <= n;j++)
{
if(i == j) continue;
for(int k = ;k < s[i].length();k++)
{
string ss = s[j].substr(k)+s[j].substr(,k);
if(ss == s[i])
{
sum += k;
break;
}
}
}
ans = min(ans,sum);
}
cout << ans << endl;
return ;
}
C.这道题首先注意负数和0的gcd,可以用__gcd尝试一下。
先判断初始的gcd是否大于1,若大于1,直接YES。
否则,剩下的数我们只用考虑它们的奇偶性。
相邻两个分为4中情况:
①奇奇 直接操作这两个位置 ans+1
②偶偶 不用动
③奇偶 操作两次变成奇奇 ans+2
④偶奇 考虑到最少的操作次数,把奇与其后面的数操作,若奇已经是最后一位,偶奇操作两次,变成奇奇
#include<bits/stdc++.h>
using namespace std; int n,a[]; int main()
{
ios::sync_with_stdio(false);
cin >> n;
cin >> a[];
int t = a[];
for(int i = ;i <= n;i++)
{
cin >> a[i];
t = __gcd(t,a[i]);
}
if(t > )
{
cout << "YES" << endl << << endl;
return ;
}
int ans = ;
for(int i = ;i < n;i++)
{
if(a[i]% && a[i+]% == )
{
ans += ;
}
else if(a[i]% && a[i+]%)
{
ans++;
a[i+]++;
}
}
if(a[n]%) ans += ;
cout << "YES" << endl << ans << endl;
return ;
}
D.我们对个数分奇偶。
若是奇数个:
对A排序,A1对应下标加入,剩下偶数个数,两两分,每组取B中最大的那个下标。
若是偶数个:
对A排序,A1对应下标加入,剩下n-2个跟上面相同操作,An对应下标加入。
这样操作的结果肯定是符合要求的。
#include<bits/stdc++.h>
using namespace std; int n,b[],c[];
struct xx
{
int x,id;
friend bool operator <(xx a,xx b)
{
return a.x > b.x;
}
}a[]; vector<int> ans; int main()
{
ios::sync_with_stdio(false);
cin >> n;
long long sum1 = ,sum2 = ;
for(int i = ;i <= n;i++) cin >> a[i].x,a[i].id = i;
for(int i = ;i <= n;i++) cin >> b[i];
sort(a+,a++n);
ans.push_back(a[].id);
for(int i = ;i <= n;i += )
{
if(i == n) ans.push_back(a[i].id);
else
{
if(b[a[i].id] > b[a[i+].id]) ans.push_back(a[i].id);
else ans.push_back(a[i+].id);
}
}
cout << ans.size() << endl;
for(int i = ;i < ans.size();i++) cout << ans[i] << " ";
cout << endl;
return ;
}
另外还有种做法,随机大法,好厉害的样子。
#include<bits/stdc++.h>
using namespace std; int n,a[],b[],c[]; int main()
{
ios::sync_with_stdio(false);
cin >> n;
long long sum1 = ,sum2 = ;
for(int i = ;i <= n;i++) cin >> a[i],sum1 += a[i];
for(int i = ;i <= n;i++) cin >> b[i],sum2 += b[i];
int k = n/+;
for(int i = ;i <= n;i++) c[i] = i;
while()
{
long long x1 = ,x2 = ;
for(int i = ;i <= k;i++)
{
x1 += a[c[i]];
x2 += b[c[i]];
}
if(x1* > sum1 && x2* > sum2)
{
cout << k << endl;
for(int i = ;i <= k;i++) cout << c[i] << ' ';
cout << endl;
return ;
}
random_shuffle(c+,c++n);
}
return ;
}
Codeforces_798的更多相关文章
随机推荐
- 小小知识点(三十)集中式大规模和无小区大规模MIMO
集中式大规模MIMO 同一小区的所有接入点( access point,AP) 布置在同一个基站( base station,BS) 中,并且 AP 之间的间距非常小,这种布置方式称为集中式大规模MI ...
- html 拨打电话
其实就一行 你们别想太复杂 直接在手机中访问 点击a标签(如果你在pc端我就没话说了) <a href="tel:13999999999"></a>
- 天梯 L2 这是二叉搜索树吗?
L2-004 这是二叉搜索树吗? (25 分) 一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点, 其左子树中所有结点的键值小于该结点的键值: 其右子树中所有结点的键值大于等于该结点的 ...
- 前端Tips#4 - 用 process.hrtime 获取纳秒级的计时精度
本文同步自 JSCON简时空 - 前端Tips 专栏#4,点击阅读 视频讲解 视频地址 文字讲解 如果去测试代码运行的时长,你会选择哪个时间函数? 一般第一时间想到的函数是 Date.now 或 Da ...
- python暴力破解压缩包密码
啥也不说,直接上代码 #-*-coding:utf-8-*- import zipfile #生成1-999999的数字密码表, 要是有别的密码类型,对密码表改造一下就可以了,也可以上网下载某些类型的 ...
- Spring Boot2 系列教程 (五) | yaml 配置文件详解
自定义属性加载 首先构建 SpringBoot 项目,不会的看这篇旧文 使用 IDEA 构建 Spring Boot 工程. 首先在项目根目录 src >> resource >&g ...
- VMware Workstation CentOS7 Linux 学习之路(5)--Docker安装与使用
一.安装与配置 1.安装依赖包 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 2.设置阿里云镜像源 sudo yum ...
- Linux 编程题
1. 产生一个进程树,父进程有2个子进程,这2个子进程分别又有2个子进程,每个进程休眠5秒后退出,并在退出前打印自己的进程id号. # include<stdio.h> # include ...
- IDEA 公司推出新字体,极度舒适~
这几天炒得沸沸扬扬的 Intellij IDEA 公司 JetBrains 推出了一种新字体:JetBrains Mono,据说它是专为开发人员设计的,下面栈长带大家一起来吃个瓜. JetBrains ...
- 洛谷 UVA1395 苗条的生成树 Slim Span
题目链接 题目描述 求所有生成树中最大边权与最小边权差最小的,输出它们的差值. 题目分析 要求所有生成树中边权极差最小值,起初令人无从下手.但既然要求所有生成树中边权极差最小值,我们自然需要对每一棵生 ...