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的更多相关文章
随机推荐
- Using TFRecords and tf.Example
-----这篇其实是TensorFlow的官方tutorials,由于没有翻译,笔者姑且翻译一下,用来日后思考.------- 原址:https://www.tensorflow.org/tutori ...
- .Net Core Linux 下面的操作
这里以 Ubuntu 8.04版本为例: 1. 注册 Microsoft 密钥 注册产品存储库 安装必需的依赖项 wget -q https://packages.microsoft.com/ ...
- 用Decorator实现依赖注入,像Java一样写后台
最近闲来无事,突发奇想,也顺便练练手,于是就萌生了,能否用typescript的decorator写一个Nodejs SpringMVC,通过依赖注入,自动实现文件加载,实例化等.然后就有了这个项目. ...
- MVC 统一验证Token demo
/// <summary> /// 获取token /// </summary> /// <param name="staffId"></ ...
- Java代码调用Shell脚本并传入参数实现DB2数据库表导出到文件
本文通过Java代码调用Shell脚本并传入参数实现DB2数据库表导出到文件,代码如下: import java.io.File; import java.io.IOException; import ...
- Go和Java的性能对比,真的如此吗?
前两天我看到了一篇文章,测试Java和Go和Python的性能,其测试内容是一个排序,排序一亿次,然后看那个语言耗时最短,我先贴一下这个文章的测试结果,Java竟然比Go快了一倍不止,Go不是号称接近 ...
- vPlayer 模块Demo
本文出自APICloud官方论坛 vPlayer iOS封装了AVPlayer视频播放功能(支持音频播放).iOS 平台上支持的视频文件格式有:WMV,AVI,MKV,RMVB,RM,XVID,MP4 ...
- 通过核心API启动单个或多个scrapy爬虫
1. 可以使用API从脚本运行Scrapy,而不是运行Scrapy的典型方法scrapy crawl:Scrapy是基于Twisted异步网络库构建的,因此需要在Twisted容器内运行它,可以通过两 ...
- 通过VS2019使用Web部署发布.net core程序
服务器:Windows Server2012R2 服务器已安装好IIS 需要启用Web Management Service 与 Web部署代理服务 服务器默认是没有Web部署代理服务的 需要安装 ...
- 【WPF学习】第十三章 理解路由事件
每个.NET开发人员都熟悉“事件”的思想——当有意义的事情发生时,由对象(如WPF元素)发送的用于通知代码的消息.WPF通过事件路由(event routing)的概念增强了.NET事件模型.事件路由 ...