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)