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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 算法设计与分析 - 主定理Master theorem (分治法递推时间复杂度)
英文原版不上了 直接中文 定义 假设有递推关系式T(n)=aT(n/b)+f(n) 其中n为问题规模 a为递推的子问题数量 n/b为每个子问题的规模(假设每个子问题的规模基本一样) f(n)为递推以外 ...
- NodeJS各个平台安装详细
http://www.runoob.com/nodejs/nodejs-install-setup.html 记录
- jenkins 构建历史 显示版本号
0 jenkins 安装此插件: 此插件名为 " groovy postbuild " 1 效果图: 2 安装插件: 系统管理 --> 插件管理 --> 可选 ...
- Kubernetes学习笔记之认识Kubernetes组件
前言:笔记知识点来源于Kubernetes官方文档说明,链接:https://kubernetes.io/docs/concepts/overview/components/ ,本记录仅仅是学习笔记记 ...
- Java 使用URL类通过url下载网络资源
主要用到的类 地址类: URL http类: HttpURLConnection 输入流: InputStream 输出流: FileOutputStream 上代码 package com.demo ...
- iostat的输出
第一行显示的时子系统启动以来的平均值,接下来的报告显示了增量的平均值,每个设备一行 Device: rrqm/s wrqm/s r/s w/s rsec/s ...
- Springboot之文件监控
背景:在实际环境部署构成中,由于特殊网络环境因素,有很多服务器之间的网络都是单向的,不能互相访问的,只有通过特定技术手段做到文件的单项摆渡,这就需要在两台服务器上分别写序列化程序和反序列化程序,这里不 ...
- kubernets之job资源
一 介绍job资源 1.1 前面介绍的RC,RS,DS等等,管控的pod都是需要长期持久的运行的应用,但是尝试考虑另外一种场景,在微服务的场景下,有些pod的作用就是需要 执行完一些命令之后正常 ...
- EXPORT和IMPORT使用示例
1 report ztestprog. 2 data:begin of itab1 occurs 0, 3 ff(10), 4 end of itab1. 5 data:itab2 like itab ...
- 哈佛商学院MBA管理课程
课程示例:向上管理 课程 什么是向上管理? 了解自己和上司 建立合作关系 与上司进行有效沟通 管理糟糕的上司 向上管理课程内容: 全部课程目录 全部为离线文件(可有偿提供) 包括课程的全部内容,视频. ...