Codeforces Round #630 (Div. 2)
题目链接:https://codeforces.com/contest/1332
A. Exercising Walk
可走的最远距离:左:x-x1,右:x2-x,下:y-y1,上:y2-y
如果可以移动,通过折返行走,两个相对方向至少有一个可以消为0,然后看余下步数是否小于等于该方向可走的最远距离,类似于一种模拟的做法,好多大佬都是直接结论QAQ。
#include <bits/stdc++.h>
using namespace std; void solve()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int x,y,x1,x2,y1,y2;
cin>>x>>y>>x1>>y1>>x2>>y2; int l1=max(x-x1,x2-x),l2=max(y-y1,y2-y);
if(l1>0){
int mi=min(a,b);
a-=mi,b-=mi;
if(a>0&&a<=x-x1) a=0;
if(b>0&&b<=x2-x) b=0;
} if(l2>0){
int mi=min(c,d);
c-=mi,d-=mi;
if(c>0&&c<=y-y1) c=0;
if(d>0&&d<=y2-y) d=0;
} if(a||b||c||d) cout<<"No\n";
else cout<<"Yes\n";
} int main()
{
int t;cin>>t;
while(t--)
solve();
return 0;
}
B. Composite Coloring
题面其实暗示得非常明确:给你一个合数数组,最多染11种颜色,相同颜色gcd大于1。
为什么是11?因为平方小于1000的质因数只有11个:
2,3,5,7,11,13,17,19,23,29,31。
因为每个数可以被分解成质因数之积,最小质因数相同的染一个颜色即可。
#include <bits/stdc++.h>
using namespace std; void solve()
{
int n;cin>>n;
int res[n]={}; int color=0;
map<int,int> m; for(int i=0;i<n;i++){
int t;cin>>t;
for(int j=2;j<=t;j++){
if(t%j==0){//j为t的最小质因数
if(m[j]) res[i]=m[j];
else res[i]=m[j]=++color;
break;
}
}
} cout<<color<<"\n";
for(int i=0;i<n;i++) cout<<i<<" \n"[i==n-1];
} int main()
{
int t;cin>>t;
while(t--)
solve();
return 0;
}
C. K-Complete Word
每次操作如下:
- 回文:取两端
- 周期:取两端向另一端的周期字符
由题意这些字符必须相同,因为要最小替换次数,统计每个字母,换成出现次数最多的即可。
#include <bits/stdc++.h>
using namespace std; void solve()
{
int n,k;cin>>n>>k;
string s;cin>>s; int ans=0;
bool vis[n]={}; for(int i=0;i<n;i++)
{
if(vis[i]) continue; vector<char> v; for(int j=i;j<n;j+=k)
if(!vis[j]){
v.push_back(s[j]);
vis[j]=true;
}
for(int j=n-i-1;j>=0;j-=k)
if(!vis[j]){
v.push_back(s[j]);
vis[j]=true;
} int mx=0,cnt[26]={};
for(char c:v) mx=max(mx,++cnt[c-'a']);
ans+=int(v.size())-mx;
}
cout<<ans<<"\n";
} int main()
{
int t;cin>>t;
while(t--)
solve();
return 0;
}
D. Walk on Matrix
该dp代码会因为追求当前的最大与值而舍弃掉会使答案更大的较小值,如:
$\begin{bmatrix} 0 & 011 & 0 \\ 100 & 111 & 011 \end{bmatrix}$
所以可以构造:
$\begin{bmatrix} inf+k & k &inf \\ inf & inf+k &k \end{bmatrix}$
#include <bits/stdc++.h>
using namespace std;
const int inf=1<<17;
int main()
{
int k;cin>>k;
cout<<"2 3\n";
cout<<(inf+k)<<' '<<k<<' '<<inf<<"\n";
cout<<inf<<' '<<(inf+k)<<' '<<k;
return 0;
}
Codeforces Round #630 (Div. 2)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- HSRP技术(热备份)学习总结
热备份学习视频https://www.bilibili.com/video/BV1i7411G7vm?p=78 • 命令: ○ int fa0/x ○ standby 1 ...
- FastApi学习(一)
前言 学习不止 正文 介绍 FastApi是PythonWeb框架的'新晋干员',虽然年轻但是很能打 目前已有 12k start GitHub 官网 为什么说他能打呢?它内部使用了 Python 的 ...
- kubernets之Deployment资源
一 声明式的升级应用 1.1 回顾一下kubernets集群里面部署一个应用的形态应该是什么样子的,通过一副简单的图来描述一下 通过RC或者RS里面的模板创建了三个pod,之后通过一个servci ...
- 目录遍历 - Pikachu
概述: 在web功能设计中,很多时候我们会要将需要访问的文件定义成变量,从而让前端的功能便的更加灵活. 当用户发起一个前端的请求时,便会将请求的这个文件的值(比如文件名称)传递到后台,后台再执行其对应 ...
- 权限管理3-整合Spring Security
一.Spring Security介绍 1.框架介绍 Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安 ...
- 集成Redis缓存
一.简介 1.场景 由于首页数据变化不是很频繁,而且首页访问量相对较大,所以我们有必要把首页数据缓存到redis中,减少数据库压力和提高访问速度. 2.RedisTemplate Jedis是Redi ...
- argparse的简单使用
简单记录一下argparse的用法 这个是针对我做区块链的一些demo时需要用到的,仅把用到了的一些操作记录,argparse很强大,更多细致的操作可以参考:https://docs.python.o ...
- CentOS7,非LVM根分区扩容步骤:
1.查看现有的分区大小 非LVM分区,目前磁盘大小为40G,根分区总容量为40G,(是自定义分区安装的) 2.关机增加磁盘大小至100G 如果你们是vmwaer虚拟软件安装的那如下入扩容: 3.查看磁 ...
- Jmeter函数助手大全
__BeanShell 入参:BeanShell语法的程序语句或者Bean Shell脚本文件 示例: ${__BeanShell(123*456,)}:返回56088: ${__BeanShell( ...
- centos 7.0 ping百度提示:ping: www.baidu.com: Name or service not known
解决方法一: 添加dns服务器 vi /etc/resolv.conf 在文件中添加如下两行: nameserver 8.8.8.8 nameserver 8.8.4.4 保存退出,重启服务器.之后再 ...