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语言入门篇-命令 与 语法
一.命令基础 1. go run : 用于运行命令源码文件(如:go run helloworld.go) 只能接受一个命令源码文件以及若干个库源码文件作为文件参数 其内部操作步骤: (1)先编译源码 ...
- mysql先分组,然后取每个分组中的第2大的记录
文章参考http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/ 首先建表: ...
- Java8---函数式编程-示例
// Java8函数式编程示例—(Predicate.Stream.Optional) https://blog.csdn.net/weixin_41950473/article/details/84 ...
- P1507NASA食物
这道题是一个01背包的延伸题,只要透彻理解了,就不难了. 这个题有两个T,一个是体积一个是质量,所以这时候我们必须要加一个for了,同时要优化空间(三维降二维),然后用f[j][k]来表示当体积为j, ...
- arm初识
一.CPU从指令集角度分类 1.1. CISC (X86) 1.1. 1. CISC CPU 指complex instruction set computer复杂指令集CPU 1.1.2. CIS ...
- php批量POST修改
这是一个thinkphp中的批量修改的案例: 如需要删除多项,或者同时修改多项记录 要点: 前端表单中name要加[],如:<input type="hidden" name ...
- 7.golang的字符串 string
golang 字符串为不可变的量 ,字符串定义要使用双引号 package main import "fmt" func main() { var xx string = 'xxx ...
- shell学习笔记1---shell编程基础
Shell是什么? Shell 是一个应用程序,它连接了用户和 Linux 内核,让用户能够更加高效.安全.低成本地使用 Linux 内核,这就是 Shell 的本质. Shell 本身并不是内核的一 ...
- 【ES6】对象的新功能与解构赋值
ES6 通过字面量语法扩展.新增方法.改进原型等多种方式加强对象的使用,并通过解构简化对象的数据提取过程. 一.字面量语法扩展 在 ES6 模式下使用字面量创建对象更加简洁,对于对象属性来说,属性初始 ...
- ajax后台请求两种方法(js和jQuery)
(1)js的ajax var xmlHttp; if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ...