题目链接: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. git的基础知识

    git 分布式版本控制工具 具备的功能 协同开发 多人并行不悖修改服务器端的同一个文件 数据备份 不仅保持目录和文件当前状态,还能保存每一个提交的历史版本 版本管理 保存每一个版本的文件信息的时候做到 ...

  2. LInux维护一:VirtualMachine磁盘扩容

  3. Tengine 四层代理:

    Tengine 四层代理: 1 ) 安装tengine ( nginx1.9 以上版本 编译以后要支持stream 模块) 1.1 ) tengine(nginx) 一定要是nginx-1.9.X 以 ...

  4. Java 使用 commons-fileupload 实现文件上传工具类

    依赖包 文件上传可以使用 Apache 文件上传组件, commons-fileupload, 它依赖于 commons-io commons-io.jar: https://repo1.maven. ...

  5. 利用Numpy求解投资内部收益率IRR

    一. 内部收益率和净现值 内部收益率(Internal Rate of Return, IRR)其实要和净现值(Net Present Value, NPV)结合起来讲.净现值指的是某个投资项目给公司 ...

  6. CTFshow-萌新赛逆向_flag白给

    查看题目信息 下载后得到一个flag.exe文件,进行测试 使用PEiD查壳 发现一个upx的壳 使用命令进行解壳 upx -d 拿到一个无壳的程序 放进OD打开,查找关键词 发现信息 成功拿到序列号 ...

  7. WeihanLi.Npoi 1.14.0 Release Notes

    WeihanLi.Npoi 1.14.0 Release Notes Intro 周末更新了一下项目,开始使用可空引用类型,并且移除了 net45 的支持,仅支持 netstandard2.0 Cha ...

  8. Golang应用性能问题排查分析

    背景 公司有一个使用golang开发的采集模块,负责调用多个外部系统采集数据:最近做了一次架构上的调整,将采集模块分成api.job两个子模块,并部署到容器中,拆分前部署在虚机上. 现象 部分采集任务 ...

  9. DDIC_TYPELENG_INCONSISTENT错误的解决办法

    当执行某个TCODE,例如SM66,出现类似如下的dump界面 大概意思就是说是ddic种的某个数据类型有问题,可能是数据结构,可能是数据元素或者是表等等 通过查阅资料了解到,对于note122290 ...

  10. python(paramiko模块的简单使用)

    #通过paramiko模块连接主机运行bash命令 import paramiko hostname = '192.168.88.31' port = 22 username = 'root' pas ...