Codeforces Round #351(Div 2)
熬到半夜打结果前一个小时提交代码的页面根本加载不进去,D题写完还因为小点没判被hack掉了。。。
rating什么的都是身外之物了,于是乎喜闻乐见地又掉回绿名了。
A题:
*题目描述:
Bear看一场90分钟的比赛,有n个有趣的事件的时间点,Bear如果连续15分钟没有看到有趣的事件,那么它就会关掉电视,问Bear最多可以看多长时间的电视?
*题解:
模拟,记得判最后一个点到90分钟的距离。
*代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#ifdef CT
#define debug(...) printf(__VA_ARGS__)
#define setfile()
#else
#define debug(...)
#define filename ""
#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
#endif
#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1 << 15], *S = B, *T = B;
inline int FastIn()
{
R char ch; R int cnt = 0; R bool minus = 0;
while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ? minus = 1 : cnt = ch - '0';
while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus ? -cnt : cnt;
}
int main()
{
// setfile();
R int n = FastIn(), last = 0;
for (R int i = 1; i <= n; ++i)
{
R int t = FastIn();
if (t - last > 15) return !printf("%d\n",last + 15 );
last = t;
}
if (90 - last > 15) return !printf("%d\n",last + 15 );
puts("90");
return 0;
}
B题:
*题目描述:
有n个题目和m种关系,每种关系表示两个题目是相似的。求所有的二分图的数量,同时要保证其中一个集合的点的编号都大于另一个集合的点的编号。
*题解:
我的第一反应是图论的题,但是想得非常复杂,然而zzx一眼秒题,把问题转化成区间上的问题。
*代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#ifdef CT
#define debug(...) printf(__VA_ARGS__)
#define setfile()
#else
#define debug(...)
#define filename ""
#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
#endif
#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1 << 15], *S = B, *T = B;
inline int FastIn()
{
R char ch; R int cnt = 0; R bool minus = 0;
while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ? minus = 1 : cnt = ch - '0';
while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus ? -cnt : cnt;
}
int main()
{
// setfile();
R int n = FastIn(), m = FastIn();
R int left = 1, right = n;
for (R int i = 1; i <= m; ++i)
{
R int l = FastIn(), r = FastIn();
cmax(left, dmin(l, r));
cmin(right, dmax(l, r));
}
printf("%d\n",dmax(right - left, 0) );
return 0;
}
C题:
*题目描述:
有n个数,每个数代表一种颜色,颜色的范围在1~n之间。问每种颜色在多少个区间内是众数(如果有多个众数则取较小的那个)。
*题解:
直接暴力搞,枚举左端点,每次把出现的数计到一个数组里面,然后用一个变量维护出现次数的最大值。
*代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#ifdef CT
#define debug(...) printf(__VA_ARGS__)
#define setfile()
#else
#define debug(...)
#define filename ""
#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
#endif
#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1 << 15], *S = B, *T = B;
inline int FastIn()
{
R char ch; R int cnt = 0; R bool minus = 0;
while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ? minus = 1 : cnt = ch - '0';
while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus ? -cnt : cnt;
}
int main()
{
// setfile();
R int n = FastIn();
for (R int i = 1; i <= n; ++i)
t[i] = FastIn();
for (R int i = 1; i <= n; ++i)
{
R int maxx = 0, node;
for (R int j = 1; j <= n; ++j) cnt[j] = 0;
for (R int j = i; j <= n; ++j)
{
++cnt[t[j]];
maxx < cnt[t[j]] || (maxx == cnt[t[j]] && t[j] < node) ? maxx = cnt[t[j]], node = t[j] : 0;
ans[node]++;
}
}
for (R int i = 1; i <= n; ++i) printf("%d ",ans[i] );
return 0;
}
D题:
*题目描述:
请你构造一幅图,这幅图满足:节点数为n,边数小于等于m,同时,存在一条路径,可以从a经过所有的节点仅一次到达b,也可以从c经过所有的节点仅一次然后到达d。
*题解:
数学构造题。除了a,b,c,d的点先构一条链,然后链的一头连a,c,另一头连b,d,然后再把a和c,b和d连起来(这里建议画一副图来理解)。于是边就变成了n+1条,否则就不成立。(我sb了没有判n=4的情况,即都是无解,结果过了pretest完立马被人x掉,直至比赛结束一直没有调出来)
*代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#ifdef CT
#define debug(...) printf(__VA_ARGS__)
#define setfile()
#else
#define debug(...)
#define filename ""
#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
#endif
#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1 << 15], *S = B, *T = B;
inline int FastIn()
{
R char ch; R int cnt = 0; R bool minus = 0;
while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ? minus = 1 : cnt = ch - '0';
while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus ? -cnt : cnt;
}
int main()
{
// setfile();
R int n = FastIn(), m = FastIn();
R int a = FastIn(), b = FastIn(), c = FastIn(), d = FastIn();
if (m < n + 1 || n == 4)
{
puts("-1");
return 0;
}
printf("%d ",a );
printf("%d ",c );
for (R int i = 1; i <= n; ++i) if (i != a && i != b && i != c && i != d) printf("%d ",i );
printf("%d ",d );
printf("%d\n",b );
printf("%d ",c );
printf("%d ",a );
for (R int i = 1; i <= n; ++i) if (i != a && i != b && i != c && i != d) printf("%d ",i );
printf("%d ",b );
printf("%d\n",d );
return 0;
}
Codeforces Round #351(Div 2)的更多相关文章
- [Codeforces Round #351 Div. 2] 673A Bear and Game
A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 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后和给 ...
随机推荐
- YARN日志聚合相关参数配置
日志聚合是YARN提供的日志中央化管理功能,它能将运行完成的Container/任务日志上传到HDFS上,从而减轻NodeManager负载,且提供一个中央化存储和分析机制.默认情况下,Contain ...
- 【Qt开发】Qt Creator在Windows上的调试器安装与配置
Qt Creator在Windows上的调试器安装与配置 如果安装Qt时使用的是Visual Studio的预编译版,那么很有可能就会缺少调试器(Debugger),而使用MSVC的Qt对应的原生调试 ...
- 【Linux开发】Linux下jpeglib库的安装详解
Linux下jpeglib库的安装详解 首先要下载所需的库压缩包:jpegsrc.v6b.tar.gz或 jpegsrc.v8b.tar.gz 然后将下载的压缩包随便放在和解压到你喜欢的地方. # t ...
- Grafana配置文件
配置文件位置 /usr/local/opt/grafana/share/grafana/default.ini /usr/local/etc/grafana/grafana.ini 配置文件调用顺序 ...
- Spark启动流程(Standalone)- master源码
Master源码 package org.apache.spark.deploy.master //伴生类 private[deploy] class Master( override val rpc ...
- php读取excel文件并导入数据库(表头任意设定)
最近收到一个很奇葩的需求,要求上传excel员工工资表,表格表头不固定,导入后字段名为表头的拼音,每月导入一次,当月重复导入则覆盖现有的当月表头,并且可以按照在界面上按照月份筛选显示,我写的代码主要包 ...
- [LeetCode] 164. 最大间距
题目链接 : https://leetcode-cn.com/problems/maximum-gap/ 题目描述: 给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值. 如果数组元素个数 ...
- 基于RSA的前后端登陆密码加密JAVA实现(转)
RSA加密算法简介 SA加密算法是一种非对称加密算法.在公开密钥加密和电子商业中RSA被广泛使用.对极大整数做因数分解的难度决定了RSA算法的可靠性.换言之,对一极大整数做因数分解愈困难,RSA算法愈 ...
- 31. Next Permutation (JAVA)
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- 基于TCP/UDP协议的socket
基于TCP协议的socket tcp是基于链接的,必须先启动服务端,然后再启动客户端去链接服务端 server端 import socket sk = socket.socket() sk.bind( ...