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

是一个比较简单的构造题,我写搓了,但是很好写,就是一条横线就可以了。

F. K-th Path

这个是求第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 补题的更多相关文章

  1. Codeforces Round #555 (Div. 3) C1,C2【补题】

    D1:思路:L,R指针移动,每次选最小的即可. #include<bits/stdc++.h> using namespace std; #define int long long #de ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

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

  4. Codeforces Round #575 (Div. 3)

    本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...

  5. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题

    D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...

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

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

  8. Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)

    C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard inpu ...

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

随机推荐

  1. IE各版本CSS Hack(兼容性处理)语法速查表

    为了兼容IE各个版本,需要在CSS中添加额外的代码,比如以前常用的_width.之所以工作,是因为浏览器会忽略不能解析的样式规则,因此举个例子来说,把_width写在width下面,对于非IE浏览器会 ...

  2. BeanShell计算支付价格

    问题:需要获取支付价格,而支付价格是商品价格*折扣 解决:先将商品价格和折扣获取出来,然后使用BeanShell将两个值相乘,获得最后的支付价格 1.使用json提取器提取商品的价格 2.使用正则表达 ...

  3. G - GCD and LCM 杭电

    Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, sa ...

  4. 9.回文数-LeetCode

    判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121输出: true示例 2: 输入: -121输出: false解释: 从左向右读, ...

  5. Unity ML-agents 一、初次尝试

    前言 曾在高二寒假的时候,跟表哥在外面玩,当时他问我有没有想过以后要做什么,我愣了一下,回答不上来.是的,从没想过以后要做什么,只是一直在完成学校.老师安排的任务,于是那之后半年,我一直在思考,大学要 ...

  6. 小知识点:session的存放位置

    在php.ini里的配置session.save_path是注释掉的,那么Seesion保存的路径在不同类型操作系统保存在什么位置? Linux: /tmp 或 /var/lib/php/sessio ...

  7. [腾讯云]简单在腾讯云 CenTOS7.0 安装Nginx,Mysql(MariaDB),Memcache,解析PHP!

    1.安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等. yum install epel-release 2.安装Nginx a) yum install n ...

  8. 人体和电脑的关系——鸟哥的LINUX私房菜基础学习篇读书笔记

    CUP=脑袋: 每个人会做的事情都不一样(指令集的差异),但主要都是通过脑袋来判断与控制身体各部分的行动 内存=脑袋中存放正在思考的数据区块: 在实际活动过程中,我们的脑袋需要有外界刺激的数据(例如光 ...

  9. spark 集群优化

    只有满怀自信的人,能在任何地方都怀有自信,沉浸在生活中,并认识自己的意志. 前言 最近公司有一个生产的小集群,专门用于运行spark作业.但是偶尔会因为nn或dn压力过大而导致作业checkpoint ...

  10. 手把手编写自己的PHP MVC框架实例教程

    1 什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式. MVC把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Contro ...