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的更多相关文章
随机推荐
- hadoop传递参数方法总结
转自:http://blog.csdn.net/xichenguan/article/details/22162813 写MapReduce程序通常要传递各种各样的参数,选择合适的方式来传递参数既能提 ...
- 命令别名设定:alias,unalias 历史命令:history
1.别名设定举例 alias lm=‘ls -al | more’ 还可以取代现有指令 alias rm='rm -i' 查询现有别名 alias 取消别名 unalias lm 2.历史命令:his ...
- 【记】创建 VirtualBoxClient COM 对象失败. 应用程序将被中断
1. 在本地64位win7系统安装VirtualBox完,启动时提示错误 原因:兼容性造成的 按照下图显示修改VirtualBox快捷方式的兼容性 2. 启动虚拟机时,提示 点击弹出框的确定按钮后,接 ...
- 迭代器使用过程中为什么抛出ConcurrentModificationException
出现的场景:在迭代器对集合进行遍历的同时,集合本身进行变更操作(add(), remove(), set()). 当正常调用时: import java.util.ArrayList; import ...
- php5.6.39 源码安装
1 安装依赖库 yum install -y autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel li ...
- 基于js的APP多语言处理
本文出自APICloud官方论坛, 感谢论坛版主哼哼哈兮 的分享. 本期分享一个js的多语言处理插件i18n.js,此插件是基于JQuery.i18n.properties修改而来的. 实现的原理 ...
- NOIP提高组2018试题解析 目录
重磅来袭! 本蒟蒻准备挑战一下NOIP2018提高组的试题啦(怎么办 我猜我连10分都拿不了) 目录: Day1 1.铺设道路 讲解 得分:100 2.货币系统 讲解 3.赛道修建 讲解 ...
- 倍增LCA模板2董博文版 伪代码
Dfs(int rt){ f[][rt]; ;k<=;k++) f[k][rt]=f[k-][f[k-][rt]]; } int LCA(int x,int y){ if(Dp[x]<Dp ...
- <s:select>自动加标签
在使用<s:select>标签时,发现页面位置不对,查看页面源码发现 <tr> <td class="tdLabel"></td> ...
- Python中的open()方法总结
总结Python中的open()方法 message= {'企业即时通信': 'aaa', '企业名称': 'bbb'} with open("..\\r.txt", " ...