Codeforces Round #350(Div 2)
因为当天的下午才看到所以没来得及请假所以这一场没有打。。。于是信息课就打了这场的模拟赛。
A题:
*题目描述:
火星上的一年有n天,问每年最少和最多有多少休息日(周六周天)。
*题解:
模7分类讨论一下。
*代码:
#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();
R int minn = n / 7 * 2, maxx = minn;
R int tmp = n % 7;
if (tmp && tmp <= 2 ) maxx += tmp;
else if (tmp) maxx += 2;
if (tmp >= 5) minn += tmp - 5;
printf("%d %d\n",minn, maxx );
return 0;
}
B题:
*题目描述:
有n个机器人,每个机器人有一个特征码,而且每个机器人都可以看见它和排在它左边的机器人的特征码。把所有的机器人看见的特征码按顺序排成一排,求第k个特征码是多少?
*题解:
等差数列随便搞一搞。。。
*代码:
#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;
}
#define maxn 100010
int a[maxn], p[maxn];
int main()
{
// setfile();
R int n = FastIn(), k = FastIn(), tmp = 0, i;
for (i = 1; i <= n + 1; ++i) p[i] = p[i - 1] + i;
for (i = 1; p[i] < k; ++i);
k -= p[i - 1];
for (R int i = 1; i <= n; ++i)
a[i] = FastIn();
printf("%d\n",a[k] );
return 0;
}
C题:
*题目描述:
有n个人和m场电影,每个人只会一种语言,m场电影有配音和字幕,如果某个人看的电影是自己会的语言配音的话,他就会很高兴,如果是自己会的语言的字幕的话,他就会一般高兴,否则就会不高兴。问:应该选择哪场电影能够使得很高兴的人最多,在保证非常高兴最多的同时,输出一般高兴的人最多的。如果有多个答案输出任意一个。
*题解:
STL题。。。sort+lower_bound,不过还要手写unique就是了。
*代码:
#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;
}
#define maxn 200010
int a[maxn], num[maxn];
struct Poi
{
int b, c, pos, num1, num2;
inline bool operator < (const Poi &that) const {return num1 < that.num1 || (num1 == that.num1 && num2 < that.num2);}
}p[maxn];
int main()
{
// setfile();
R int n = FastIn();
for (R int i = 1; i <= n; ++i)
a[i] = FastIn();
R int m = FastIn();
for (R int i = 1; i <= m; ++i)
p[i].b = FastIn(), p[i].pos = i;
for (R int i = 1; i <= m; ++i)
p[i].c = FastIn();
std::sort(a + 1, a + n + 1);
R int newn = 0;
for (R int i = 1; i <= n; ++i)
if (a[i] == a[i - 1]) ++num[newn];
else a[++newn] = a[i], num[newn] = 1;
for (R int i = 1; i <= m; ++i)
{
R int tmp = std::lower_bound(a + 1, a + newn + 1, p[i].b) - a;
if (a[tmp] == p[i].b) p[i].num1 = num[tmp];
else p[i].num1 = 0;
tmp = std::lower_bound(a + 1, a + newn + 1, p[i].c) - a;
if (a[tmp] == p[i].c) p[i].num2 = num[tmp];
else p[i].num2 = 0;
}
std::sort(p + 1, p + m + 1);
printf("%d\n",p[m].pos );
return 0;
}
D题:
*题目描述:
你制作一个曲奇需要n种配料,你还有k个可以变成任意一种配料的神奇的粉末。对于每一种配料i,你配出1份曲奇需要第i种配料ai个,而你有bi个这种配料,问:你最多可以配出多少份曲奇?
*题解:
直接二分答案,然后判断需要多少个神奇粉末,再和k比较。
*代码:
#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;
}
#define maxn 100010
int a[maxn], b[maxn], n, k;
inline bool check(R long long x)
{
R long long tmp = 0;
for (R int i = 1; i <= n; ++i)
if (b[i] < 1ll * x * a[i]) tmp += 1ll * x * a[i] - b[i];
return tmp <= k;
}
int main()
{
// setfile();
n = FastIn(), k = FastIn();
for (R int i = 1; i <= n; ++i)
a[i] = FastIn();
for (R int i = 1; i <= n; ++i)
b[i] = FastIn();
R long long l = 0, r = 2e9 + 233;
while (l < r)
{
R long long mid = l + r >> 1;
if (check(mid)) l = mid + 1;
else r = mid;
}
printf(LL"\n",l - 1 );
return 0;
}
E题:
*题目描述:
你需要写一个括号序列编辑器。你有一个长度为n的括号序列,以及m个操作,还有初始时光标的位置。每次的操作有:
1.将光标左移一位
2.将光标右移一位
3.删除光标所在的括号以及和它匹配的括号中间的部分。
*题解:
先用一个栈来匹配左右括号序列,然后再用链表维护整个括号序列。每次删除操作就在链表上进行区间删除。(我真的是数据结构写傻了,第一反应居然是Treap,后来马上发现用链表维护就可以了,最后因为边界写搓了没有在规定的时间内ac,后来调过了总算是a了)
*代码:
#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;
}
#define maxn 500010
bool br[maxn];
int last[maxn], next[maxn], stack[maxn], pr[maxn], q, m, n;
inline void print_ans()
{
for (R int i = next[0]; i <= n; i = next[i]) putchar(br[i] ? '(' : ')');
puts("");
}
int main()
{
// setfile();
n = FastIn(), m = FastIn(), q = FastIn();
for (R int i = 1; i <= n; ++i)
{
R char ch = getc();
while (ch != '(' && ch != ')') ch = getc();
br[i] = ch == '(';
last[i] = i - 1;
next[i] = i + 1;
}
next[0] = 1;
last[n + 1] = n;
R int top = 0;
for (R int i = 1; i <= n; ++i)
{
if (br[i]) stack[++top] = i;
else
{
pr[i] = stack[top--];
pr[pr[i]] = i;
}
}
for (R int i = 1; i <= m; ++i)
{
R char opt = getc();
while (opt < 'A' || opt > 'Z') opt = getc();
if (opt == 'L') q = last[q];
if (opt == 'R') q = next[q];
if (opt == 'D')
{
if (br[q])
{
last[next[pr[q]]] = last[q];
next[last[q]] = next[pr[q]];
q = next[pr[q]];
}
else
{
last[next[q]] = last[pr[q]];
next[last[pr[q]]] = next[q];
q = next[q];
}
if (q > n) q = last[n + 1];
}
}
print_ans();
return 0;
}
Codeforces Round #350(Div 2)的更多相关文章
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表
E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- Codeforces Round #350 (Div. 2) C. Cinema 水题
C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...
- Codeforces Round #350 (Div. 2) B. Game of Robots 水题
B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...
- Codeforces Round #350 (Div. 2) A. Holidays 水题
A. Holidays 题目连接: http://www.codeforces.com/contest/670/problem/A Description On the planet Mars a y ...
- Codeforces Round #350 (Div. 2) E 思维模拟
给出一个合法的括号串 有LRD三种操作 LR分别是左右移动当前位置 且合法 D为删除这个括号和里面的所有 当删除完成后 位置向右移动 如果不能移动 就向左 比赛都是很久远的事情了 写这道题也是一时兴起 ...
随机推荐
- 【Go语言】map在goroutine通信中的使用问题
简介 本篇文章的主要内容是解决go语言map在使用中遇到的两个问题,对于初学者是不可避免的坑 一.cannot assign to struct field 当map中存在struct类型的成员,如果 ...
- Centos7 搭建pptp服务器
1.检查是否支持pptp 返回ok即表示支持 modprobe ppp-compress-18 && echo ok 2.安装ppp yum install -y ppp 3.安装pp ...
- soot学习历程---(1)
今天看了soot生成手册的部分内容,简单摘录一下 Scene 表示分析所处的完整环境,可以借此设置application class(用sootclass),主类(main),point-to和cal ...
- [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Cannot access nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public) in off
这个错误是将work offline打勾引起的. 这个是离线工作模式,相当于断网,远程的jar会拉不下来.
- 有序无序Ul->Li Ol->Li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单(变形2 ---修饰)
从上面可以看出,两个问题,第一:下拉出现的太快太突然,第二:再点击下一个下拉菜单的时候,上一个不会闭合,针对这两个问题,接下来会一 一解决. 解决下拉太快: js中有个jquery效果,有一个效果是j ...
- 理解 JavaScript 闭包
这是本系列的第 4 篇文章. 作为 JS 初学者,第一次接触闭包的概念是因为写出了类似下面的代码: for (var i = 0; i < helpText.length; i++) { var ...
- Lock和synchronized的区别和使用(转发)
今天看了并发实践这本书的ReentantLock这章,感觉对ReentantLock还是不够熟悉,有许多疑问,所有在网上找了很多文章看了一下,总体说的不够详细,重点和焦点问题没有谈到,但这篇文章相当不 ...
- Luogu P2756 [网络流24题]飞行员配对方案问题_二分图匹配题解
二分图模板题 我用的是匈牙利 其实最大流也可以做 #include<iostream> #include<cstdio> #include<cstdlib> #in ...
- SSM获取前台参数的方式
1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交.若"Content-Type"="application/ ...
- js中的函数防抖与节流
一.滚动条监听的例子 写一个功能需求-- 监听浏览器滚动事件,返回当前滚条与顶部的距离,代码如下: function showTop () { var scrollTop = document.bod ...