题目链接: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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. Goland 设置代码格式化

    前言 之前一直喜欢 VsCode 的代码自动格式化和其他的一些功能 今天了解到原来 Goland 也有这些功能, 想想也对, 毕竟这么大 正文 Goland设置代码格式化 进入设置,按需选择要使用的, ...

  2. nginx日志详细说明

    Nginx日志主要分为两种:访问日志和错误日志.日志开关在Nginx配置文件(/etc/nginx/nginx.conf)中设置,两种日志都可以选择性关闭,默认都是打开的. 访问日志 访问日志主要记录 ...

  3. zabbix_agent items not supported状态

    不记得自己究竟更改了什么东西,然后突然发现所有的有关mysql的监控items都变成了not supported,怎么做不行,最后在web主页把主机删除,又重新添加一下,重新添加了一下模版就好了.这究 ...

  4. VS2019项目docker启动且访问SQLSERVER数据库配置

    VS2019编译.调试的Blazor纯前台项目,使用控制台启动,去连接纯后台的API项目,使用docker启动,并且通过EFCore访问SQLSERVER数据库,有几个地方需要修改配置: 一.前台连后 ...

  5. kubernets之secret资源

    一  对于一些保密度比较高的文件,k8s又是如何存储的呢? 针对那些保密度比较高的配置文件,例如证书以及一些认证配置不能直接存储在configmap中,而是需要存储在另外一种资源中,需要对存储在里面的 ...

  6. pandas 写csv 操作

    pandas 写csv 操作 def show_history(self): df = pd.DataFrame() df['Time'] = pd.Series(self.time_hist) df ...

  7. Leetcode53. 最大子序列和

    问题 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 代码 贪心算法 核心思想就是检查之前 i-1 的元素和,如果小于零就舍弃--对应下面第六行 ...

  8. libnum报错问题解决

    之前在使用python libnum库时报错 附上报错内容 Traceback (most recent call last) : File" D:/python file/ctf/RSA共 ...

  9. ElasticSearch7.2简单命令实操(postman版)

    使用postman访问操作ElasticSearch数据库,数据格式均为json 目录 使用postman访问操作ElasticSearch数据库,数据格式均为json 一.集群设置 1.查看集群设置 ...

  10. 使用注解的形式对token进行验证

    @[TOC](使用注解的形式对token进行验证)# 前言现在很多系统都是都用上了springboot.springcloud,系统也偏向分布式部署.管理,最早的用户令牌方案:session.cook ...