Codeforces Round #614 (Div. 2) 比赛总结

比赛情况

怒切 \(A,B,C,D\),后面 \(E,F\) 两题技术太菜不会做,不知道什么时候可以补起来。

比赛总结

事实证明:

  • 比赛前喝一瓶抗疲劳饮料对比赛状态的进入有显著效果。
  • 比赛有人陪着打对AC题目有显著效果。

说正经的:

  • 不要紧张,也不要太过放松。这样才有利于发挥出真实水平。

下面就开始 喜闻乐见 的题解吧。

A

入门题

枚举找到最近的可用楼层即可。用 \(STL\) 里面的 map 判断一个楼层是否可用使用。

Code

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
int n,S,K,ans;
void work() {
    map<int,bool> vis;
    n = read(), S = read(), K = read(); ans = INF;
    for(int i=1,x;i<=K;++i) {
        x = read(); vis[x] = 1;
    }
    for(int j=0;S+j<=n||S-j>=1;++j) {
        if(S+j <= n && !vis[S+j]) {
            ans = j; break;
        }
        if(S-j >= 1 && !vis[S-j]) {
            ans = j; break;
        }
    }
    printf("%d\n",ans);
}
int main()
{
    int T = read();
    while(T--) work();
    return 0;
}

B

贪心题

假设最优策略是:每次选一个人答错,当前剩下 \(s\) 个人时的收益就是 \(\frac{1}{s}\),答案就是 \(\sum_{i=1}^n \frac{1}{i}\)。

用数学归纳法证明这个猜想的正确性(其实也可以手动模拟+感性理解qwq)

证明:
对于 \(n=1\),答案是 \(\frac{1}{1}\),显然成立。
对于任意 \(k,k>1\),假设对 \(k-1\) 成立,下面我们证明对 \(k\) 也成立。
\(k-1\) 时的最大收益是 \(\sum_{i=1}^{k-1} \frac{1}{i}\)
如果 \(k\) 回合不取 \(\frac{1}{k}\),而是取任意正整数 \(r,r>1,\frac{r}{k}\),那么答案就是 \(\frac{r}{k}+\sum_{i=1}^{k-r}\),然而 \(\sum_{i=k-r+1}^k \frac{1}{i} > \frac{r}{k}\) (因为可以把右边写成 \(\sum_{i=1}^r \frac{1}{k}\),和式的项数是相同的,但是左边和式的每一项都大于等于右边的每一项)
所以对于 \(k,\frac{1}{k} + \sum_{i=1}^{k-1} \frac{1}{i}\) 是最大的答案。

(我的证明其实有些繁琐)

Code

#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
int n;
double sum=0;
int main(){
    n = read();
    for(double i=1;i<=n;i++){
        sum += 1 / i;
    }
    printf("%.10f\n",sum);
}

C

模拟题

把迷宫分为上下两部分,上面部分第 \(x\) 格记做 \(m_{0,x}\),下面部分第 \(x\) 个记做 \(m_{1,x}\)。

可以发现如果 \(m_{0,x}\) 是熔岩,\(m_{1,x-1},m_{1,x},m_{1,x+1}\) 就不能是熔岩,否则就输出 No

接下来就是按题意模拟。

Code

#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
const int N = 2e5+7;
int n,q,cnt;
int vis[N],ctr[N],sto[N];
int main()
{
    n = read(), q = read();
    for(int i=1;i<=q;++i) {
        int x = read(), y = read();
        if(x == 1) {
            if(vis[y] == 0) {
                vis[y] = 1;
                for(int j=-1;j<=1;++j)
                    if(y+j>=1 && y+j<=n) {
                        if(ctr[y+j] == 0 && sto[y+j]==1) {
                            ++cnt;
                        }
                        ctr[y+j]++;
                    }
            } else {
                vis[y] = 0;
                for(int j=-1;j<=1;++j)
                    if(y+j>=1 && y+j<=n) {
                        if(ctr[y+j] == 1 && sto[y+j]==1)
                            --cnt;
                        ctr[y+j]--;
                    }
            }
        } else {
            if(sto[y] == 0) {
                sto[y] = 1;
                if(ctr[y]) ++cnt;
            } else {
                sto[y] = 0;
                if(ctr[y]) --cnt;
            }
        }
        if(!cnt) puts("Yes");
        else puts("No");
    }
    return 0;
}

D

暴力枚举题

有一个技巧,看到 \(a_x,a_y >= 2\),这启发我们点数不会超过 \(\log_2 t\) 个(这是算进上一个题目学来的技巧,看题目数据qwq)。

还有一个距离性质,因为是曼哈顿距离,我们可以一个一个点得走,从 \(i\) 点走到第 \(i+1\) 点或者是走到 \(i-1\) 点,并且不走回头路。

这样我们的算法就呼之欲出了,枚举从起点走到一个点 \(P\),再枚举从点 \(P\) 向上走,向下走两种路径,统计能走的最多步数。

(我还觉得这题码力有点大qwq)

update: Wrong Answer on test 125

Code

#include<bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
const int N = 1007;
int t,cnt,ans;
struct Point {
    int x,y;
}p[N],a,b,st;
inline int dist(Point p1,Point p2) {
    return abs(p1.x-p2.x) + abs(p1.y-p2.y);
}
signed main()
{
    p[0].x = read(), p[0].y = read(), a.x = read(), a.y = read(), b.x = read(), b.y = read();
    st.x = read(), st.y = read(), t = read();
    int X,Y;
    for(X=a.x*p[0].x+b.x, Y=a.y*p[0].y+b.y; X<=INF && Y<=INF && X>=0 && Y>=0; X=a.x*X+b.x,Y=a.y*Y+b.y) {
        p[++cnt].x = X, p[cnt].y = Y;
        //printf("  <%lld,%lld>\n",X,Y);
    }
    //printf("Why %d %d\n",X,Y);
    //for(int i=0;i<=cnt;++i) printf("(%lld,%lld)\n",p[i].x,p[i].y);
    //printf("  INF = %lld\n",INF);
    //printf("%lld\n",cnt);
    for(int i=0;i<=cnt;++i) {
        int tmp = t, res = 1;
        tmp -= dist(st,p[i]);
        if(tmp < 0)  continue;
        while(tmp-dist(p[i],p[i+res]) >= 0 && i+res<=cnt) ++res;
        ans = max(ans,res);
        res = 1;
        while(i-res>=0 && tmp-dist(p[i],p[i-res]) >= 0) ++res;
        ans = max(ans,res);
    }
    printf("%lld\n",ans);
    return 0;
}
/*
1 1 2 2 0 0
51531 51321 5153151
*/

E

挖坑,待补

F

挖坑,待补

原文地址:https://www.cnblogs.com/BaseAI/p/12216148.html

时间: 2024-08-02 23:43:16

Codeforces Round #614 (Div. 2) 比赛总结的相关文章

Codeforces Round #614 (Div. 2) D. Aroma&#39;s Search

题目链接:http://codeforces.com/contest/1293/problem/D 题意: 给定x0,y0,ax,ay,bx,by 即一堆经验点:(x0,y0),(x1,y1)等价于(ax*x0+bx,ay*y0+by),(x2,y2)等价于(ax*x1+bx,ay*y1+by),(x3,y3)等价于(ax*x2+bx,ay*y2+by)...... 再给定xs,ys,t 即起点(xs,ys),时间t 上下左右每走一步都需要1单位时间,问在t时间内,从起点出发最多可以吃到多少个经

Codeforces Round #614 (Div. 2) C. NEKO&#39;s Maze Game

题目链接:http://codeforces.com/contest/1293/problem/C 题意:给定n,q,即给定一个2*n的格子,有q个查询. 每个查询给定一个ri和ci,ri为1或2,ci在1到n之间,即给定一个(ri,ci),该点自该查询起状态进行转变(可经过/不可经过). 如某个查询给定1,2,即点(1,2)无法经过,若之后查询再次给定1,2,则该点(1,2)可以经过. 问能否从(1,1)走到(2,n),保证给定的查询不会经过起点和终点. 思路: 由于n和q最大都是1e5,所以

Codeforces Round #614 (Div. 2) E. Xenon&#39;s Attack on the Gangs

On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free time, he decides to put on his legendary hacker "X" instinct and fight ag

Codeforces Round #614 (Div. 2)

A. ConneR and the A.R.C. Markland-N 题目链接:https://codeforces.com/contest/1293/problem/A 题意: 有一个长为 n 的楼层,其中有 k 个楼层没有餐厅 ,你现在在 s 层,问你最少走多少个楼层可以到达餐厅吃饭 分析: 因为 k 只有 1000,所以直接往 s 层上下方找(当找到 0 或者 n + 1 时说明这个方向没有答案) #include<bits/stdc++.h> using namespace std;

Codeforces Round #606 Div. 2 比赛情况

比赛情况 bq. A题 Wrong Answer on test 2 , E题sb题没切.bqbqbq. 比赛总结 bq. 那就直接上题解吧!^-^ A 数位dp,分类讨论. Talk is cheap.Show me the code. B 我们把数值一样的数放在一起,扔进堆里.按数值从大到小处理就OK了. 注意值域比较大,用一下 \(STL\) 里面的 map. Talk is cheap.Show me the code. #include<bits/stdc++.h> using na

Codeforces Round #614 (Div. 2) B - JOE is on TV!

原题题面:https://codeforces.com/contest/1293/problem/B 解题思路: Σi=1~n 1/i ??? 1 /* 2 Written By. StelaYuri 3 On 2020/01/19 4 */ 5 #include<bits/stdc++.h> 6 using namespace std; 7 typedef long long ll; 8 int a[1005],b[1005]; 9 void solve(){ 10 int n,i; 11

Codeforces Round #614 (Div. 2) A - ConneR and the A.R.C. Markland-N

原题题面:https://codeforces.com/contest/1293/problem/A 题目大意: ConneR老师想吃东西,他现在在大楼的第s层,大楼总共有n层,但是其中有k层的餐厅关门了. 然后给了这k层关门的餐厅分别所在的楼层. 所以问ConneR老师最少得往上(或者往下)走几层楼,才能到最近的还开门的餐厅就餐? 解题思路1: 对于关闭的k层,存在数组a里排序.(放在1~k的位置) 先循环一遍数组a,看看s层是否存在于a数组里,如果不存在,直接输出0作为答案. 如果存在,开始

Codeforces Round #614 (Div. 2) A( A - ConneR and the A.R.C. Markland-N)

A - ConneR and the A.R.C. Markland-N 题目链接:http://codeforces.com/contest/1293/problem/A 题意:一栋楼房有n(1~n)层,有个人身处s楼,现在想要到餐厅吃饭,可是现在有k个餐厅关闭的,问你该人至少爬几层楼梯才能到开放的餐厅吃饭 思路:...这题暴力没戏..又是超时又是超内存...分两种,一个是往上找出最小的i-s即可,一个是往下找,找出最小的s-i即可,,用了数组还是超时..用了map就过了 // // Crea

【cf比赛记录】Codeforces Round #600 (Div. 2)

Codeforces Round #600 (Div. 2) ---- 比赛传送门 昨晚成绩还好,AC A,B题,还能上分(到底有多菜) 补了C.D题,因为昨晚对C.D题已经有想法了,所以补起题来也快.(C题TLE了,D题想用并查集没好) A // http://codeforces.com/contest/1253/problem/A /* 如果YES,则b[i] - a[i] 在一个区间里的差肯定是相同的且不小于0 */ #include<iostream> #include<cst