Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3)
这个div3打的太差了,心态都崩了。
B. Odd Sum Segments
B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分成x个奇数,那么这个x肯定是一个奇数,
偶数同理,如果一个偶数想分成y个奇数,那么这个y肯定是一个偶数。
所以数奇数的个数,如果奇数有x个,x是偶数,那么k一定是一个偶数,如果x是一个奇数,那么k肯定是一个奇数。
输出也比较简单,因为奇数要分成奇数个,所以可以前面每组都是含有一个奇数,最后肯定会有奇数个奇数的。
偶数同理。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
vector<int>e;
int main()
{
int q;
scanf("%d", &q);
while(q--)
{
int n, k;
scanf("%d%d", &n, &k);
e.clear();
for(int i=;i<=n;i++)
{
ll x;
scanf("%lld", &x);
if(x&) e.push_back(i);
}
int len = e.size();
if (k > len) printf("NO\n");
else if (((len & ) && (k & )) || ((len % == ) && (k % == ))) {
printf("YES\n");
for (int i = ; i < k - ; i++) printf("%d ", e[i]);
printf("%d\n", n);
}
else printf("NO\n");
}
}
B
C. Robot Breakout
这个C题当时没有写出来,因为我感觉要分很多种情况来讨论,实际上并不需要。
这个题目我只要给x y 的上下界限制范围就可以了,根据每一个位置出现0的情况来缩小xy的范围。
虽然这个题目比赛的时候没有写出来,不过还是很有收获的,因为我自己对于这种题目本身就不是很擅长。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
vector<int>e;
bool judge(char ch,char c)
{
if (ch == 'R'&&c == 'G') return ;
if (ch == 'G'&&c == 'B') return ;
if (ch == 'B'&&c == 'R') return ;
return ;
}
char s[maxn];
int main()
{
int q;
scanf("%d", &q);
while(q--)
{
int n;
scanf("%d", &n);
int l=-1e5, r=1e5, d=-1e5, u=1e5;
for(int i=;i<=n;i++)
{
int a, b;
scanf("%d %d", &a, &b);
for(int j=;j<=;j++)
{
int x;
scanf("%d", &x);
if (j == && x == ) l = max(l, a);
if (j == && x == ) u = min(u, b);
if (j == && x == ) r = min(r, a);
if (j == && x == ) d = max(d, b);
//printf("l=%d r=%d u=%d d=%d\n", l, r, u, d);
}
}
if (l > r || u < d) printf("0\n");
else printf("1 %d %d\n", l, u);
}
return ;
}
C
D1. RGB Substring (easy version)
这个D1 我觉得还比较难吧,自己也没有写出来,看了别人的代码,
这个题目要找这种序列,那么就可以先用一个数组存下来前面的组成完整的RGBRGBR.....的个数。
这个我觉得有一点点dp的思想,再加上前缀和,然后就可以求出来。
最后我们要求的是有m个的最小花费,这个的话就是枚举,枚举长度为m,求最小花费。
这种题目我很少做,这次没做出来,以后希望不要忘记了。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
int sum[maxn][];
char s[maxn];
int main()
{
int q;
scanf("%d", &q);
while(q--)
{
int n, m;
cin >> n >> m;
int ans = inf;
memset(sum, , sizeof(sum));
scanf("%s", s+);
for (int i = ; i <= n; i++) {
if (i % == ) {
if (s[i] == 'R') sum[i][]++;
if (s[i] == 'G') sum[i][]++;
if (s[i] == 'B') sum[i][]++;
}
if (i % == ) {
if (s[i] == 'R') sum[i][]++;
if (s[i] == 'G') sum[i][]++;
if (s[i] == 'B') sum[i][]++;
}
if (i % == ) {
if (s[i] == 'R') sum[i][]++;
if (s[i] == 'G') sum[i][]++;
if (s[i] == 'B') sum[i][]++;
}
}
for(int i=;i<=n;i++)
{
sum[i][] += sum[i - ][];
sum[i][] += sum[i - ][];
sum[i][] += sum[i - ][];
// printf("sum[%d][1]=%d\n", i, sum[i][1]);
// printf("sum[%d][2]=%d\n", i, sum[i][2]);
// printf("sum[%d][3]=%d\n", i, sum[i][3]);
}
for(int i=;i<=n;i++)
{
if(i<=m)
{
ans = min(ans, m - sum[i][]);
ans = min(ans, m - sum[i][]);
ans = min(ans, m - sum[i][]);
}
else
{
ans = min(ans, m - (sum[i][] - sum[i - m][]));
ans = min(ans, m - (sum[i][] - sum[i - m][]));
ans = min(ans, m - (sum[i][] - sum[i - m][]));
}
// printf("i=%d ans=%d\n", i, ans);
}
printf("%d\n", ans);
}
return ;
}
D1
D2和D1代码差不多,不过卡了memset,把memset换成for循环就可以了。
E. Connected Component on a Chessboard
是一个比较简单的构造题,我写搓了,但是很好写,就是一条横线就可以了。
这个是求第k短路,但是这个因为k很小,所以可以直接暴力,我用的floyed,
先把所有的点离散化了,然后再跑floyed,最后把结果存到数组里面,然后输出第k大就可以了。
这个求第k大有一个A* 算法,但是这个题目好像不可以用,因为时间复杂度太高了。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
struct node
{
int u, v;
ll w;
node(int u=,int v=,ll w=):u(u),v(v),w(w){}
}exa[maxn];
bool cmp(node a,node b)
{
return a.w < b.w;
}
int f[maxn];
int a[maxn];
ll w[][];
vector<ll>e;
int main()
{
int n, m, k, tot = ;
scanf("%d%d%d", &n, &m, &k);
for(int i=;i<=m;i++)
{
int u, v;
ll w;
scanf("%d%d%lld", &u, &v, &w);
exa[i] = node(u, v, w);
}
sort(exa + , exa + + m, cmp);
for(int i=;i<=min(k,m);i++)
{
a[tot++] = exa[i].u;
a[tot++] = exa[i].v;
}
sort(a, a + tot);
int len = unique(a , a + tot) - a;
int cnt = ;
for (int i = ; i <len; i++) {
f[a[i]] = ++cnt;
}
memset(w, inf64, sizeof(w));
for(int i=;i<=min(m,k);i++)
{
w[f[exa[i].u]][f[exa[i].v]] = exa[i].w;
w[f[exa[i].v]][f[exa[i].u]] = exa[i].w;
}
for (int i = ; i <= cnt; i++) w[i][i] = ;
for(int l=;l<=cnt;l++)
{
for(int i=;i<=cnt;i++)
{
for(int j=;j<=cnt;j++)
{
w[i][j] = min(w[i][j], w[i][l] + w[l][j]);
}
}
}
for(int i=;i<=cnt;i++)
{
for(int j=i+;j<=cnt;j++)
{
e.push_back(w[i][j]);
//printf("w[%d][%d]=%lld\n", i, j, w[i][j]);
}
}
sort(e.begin(), e.end());
// for(int i=0;i<e.size();i++)
// {
// printf("i=%d %lld\n", i, e[i]);
// }
printf("%lld\n", e[k - ]);
return ;
}
这一场打的很差,要加油啊。
Codeforces Round #575 (Div. 3) 昨天的div3 补题的更多相关文章
- Codeforces Round #555 (Div. 3) C1,C2【补题】
D1:思路:L,R指针移动,每次选最小的即可. #include<bits/stdc++.h> using namespace std; #define int long long #de ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #575 (Div. 3)
本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题
D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...
- Codeforces Round #575 (Div. 3) E. Connected Component on a Chessboard(思维,构造)
E. Connected Component on a Chessboard time limit per test2 seconds memory limit per test256 megabyt ...
- Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...
- Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)
C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard inpu ...
- Codeforces Round #575 (Div. 3) B. Odd Sum Segments (构造,数学)
B. Odd Sum Segments time limit per test3 seconds memory limit per test256 megabytes inputstandard in ...
随机推荐
- 【python实现卷积神经网络】批量归一化层实现
代码来源:https://github.com/eriklindernoren/ML-From-Scratch 卷积神经网络中卷积层Conv2D(带stride.padding)的具体实现:https ...
- stand up meeting 1/12/2016
part 组员 工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 UI测试和调整:页面跳转调整 3 查漏补缺,扫除UI b ...
- django.template.exceptions.TemplateDoesNotExist: login.html报错
前言 在某一次按以前的步骤使用Django “django.template.exceptions.TemplateDoesNotExist: login.html”错误,在以为是html文件出 ...
- UML(续)
活动图 活动图定义 活动图描述了在一个过程中,顺序的/并行的活动及其之间的关系 应用于商业过程.工作流(业务过程).复杂算法的建模 活动图是顶点和弧的集合 活动节点 动作 流 对象值 注解和约束等 建 ...
- CSS属性中的display属性浅谈;
首先我们要知道什么是块级元素和行内元素有什么区别: 承接上篇文章:(浅谈HTML和body标签) 块级元素:浏览器解析为独占一行的元素(例如:div.table.ul等.),浏览器会在该元素的前后显示 ...
- 14.移动端图片浏览组件 react-wx-images-viewer
安装 npm install --save react-wx-images-viewer 使用 import WxImageViewer from 'react-wx-images-viewer'; ...
- [javascript] jquery的父子兄弟节点查找
jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(&q ...
- [数据库]Mysql蠕虫复制增加数据
将查询出来的数据插入到指定表中,例: 将查询user表数据添加到user表中,数据会成倍增加 insert into user(uname,pwd) select uname,pwd from use ...
- 【高频 Redis 面试题】Redis 事务是否具备原子性?
一.Redis 事务的实现原理 一个事务从开始到结束通常会经历以下三个阶段: 1.事务开始 客户端发送 MULTI 命令,服务器执行 MULTI 命令逻辑. 服务器会在客户端状态(redisClien ...
- pytorch seq2seq闲聊机器人加入attention机制
attention.py """ 实现attention """ import torch import torch.nn as nn im ...