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;
#define ll long long
map<ll , int>ha;
int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        ha.clear();
        ll n , s , k ;
        cin >> n >> s >> k;
        for(int i = 1 ; i <= k ; i ++)
        {
            int x;
            cin >> x;
            ha[x] = 1;
        }
        ll now = s , ans = (0x3f3f3f3f3f3fll);
        while(ha[now])
        now ++ ;
        if(now != n + 1)
        ans = now - s;
        now = s;
        while(ha[now])
        now --;
        if(now != 0)
        ans = min(ans , s - now);
        cout << ans << ‘\n‘;
    }
    return 0;
}

B. JOE is on TV!

题目链接:https://codeforces.com/contest/1293/problem/B

题意:

当敌人总数为 i 时,如果它犯了 j(j  <= i) 个错误,则你可以获得 $\dfrac {j}{i}$ 的报酬,同时敌人数量会减少 j 。现有n个敌人,问你能获得的最大报酬为多少

分析:

(应该很很多人都是盲猜正解,比如我)

记敌人总数为 N , 若此时你要让它犯 T 个错误,则你获得的报酬为$\dfrac {T}{N}$ , 敌人总数变为 N - T。

但若你从 N 开始每次让敌人犯1个错误直到敌人总数为 N - T , 那么的获得的报酬就为 $\dfrac {1}{N}+\dfrac {1}{N-1}+\ldots +\dfrac {1}{N-T+1}$

然后可以证得 $\dfrac {T}{N}\leq \dfrac {1}{N}+\dfrac {1}{N-1}+\ldots +\dfrac {1}{N-T+1}$ (怎么证就不细说了)

所以每次只让敌人犯一个错误获得的报酬会是最大的

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n ;
    double  ans = 0;
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        ans += 1.0 / i;
    cout << ans << ‘\n‘;
    return 0;
}

C. NEKO‘s Maze Game

题目链接:https://codeforces.com/contest/1293/problem/C

题意:

有一个 2 * N 的地图,开始每个位置都是可以走的。然后地图会改变 q 次,每次改变会使一个位置改变状态(可走→不可走,不可走→可走)

问每次改变完地图后是否能从(1 , 1)走到(2 , n)

分析:

因为地图只有两行,所以无法到达终点的情况只有这些:当前位置不可走,且该位置上、下、左上、左下、右上、右下不能走,我们用 cnt 统计这些情况的总个数

那么当 cnt = 0 时,则可以到达,否则不能

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
ll mat[10][N];
int main()
{
    ll n , q , cnt = 0;
    cin >> n >> q;
    for(int i = 1 ; i <= q ; i ++)
    {
        ll x, y, z = 1;
        cin >> x >> y;
        if(x == 1) z = 2;
        if (mat[x][y])
            cnt = cnt - mat[z][y - 1] - mat[z][y] - mat[z][y + 1];
        else
            cnt = cnt + mat[z][y - 1] + mat[z][y] + mat[z][y + 1];
        if (!cnt)
            cout << "Yes" << ‘\n‘;
        else
            cout << "No" << ‘\n‘;
        mat[x][y] ^= 1;
    }
    return 0;
}

D. Aroma‘s Search

题目链接:https://codeforces.com/contest/1293/problem/D

题意:

有无数的点,第1个点的坐标为 (X1 , Y1) , 第2个点的坐标为 (X1 * ax + bx , Y1 * bx + by) , 第三个点的坐标为(X2 * ax + bx , Y2 * ay + by) ......

你的初始位置为(SX , SY) , 你每秒可以向上、向下、向左、向右移动一格。问在 T 秒内,你最多可以到达几个点

分析:

题目给的 SX、SY、T 最大可取值都为 1e16 , 且点的个数是无限的,乍一看好像会有很多种情况,但因为ax , ay 都是大于等于2的,所以横坐标和纵坐标的增长速率都大于等于 2 的幂次

而除第一个点外当横坐标或纵坐标大于 1e17 时,这个点就肯定用不上了(因为此时这个点到距离它最近的点所用的时间必然 > T),那么算下来可以使用的点顶多也就60个.

所以我们可以枚举一个起点和终点(枚举的起点和终点可以相同)

若我们到达起点 i 所用的时间和到达终点 j 所用的时间小于等于T,则我们可以到达的点的个数为 $abs\left( i-j\right) +1$ (不理解可以把顶点的分布情况画出来),然后更新一下 ans

// 比赛时用 dfs 枚举的复杂度为O( n ^ 3 )  , 虽然不会超时但是写的比较乱,所以赛后看tourist代码改了一份精简版的

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
const int N = 2e5 + 10;
const ll MAXN = 1e17;
vector<pair<ll , ll> >vec;
ll dist(ll x1 , ll y1 , ll x2 , ll y2)
{
    return abs(x1 - x2) + abs(y1 - y2);
}
int main()
{
    ll x , y , ax , ay , bx , by;
    ll sx , sy , t;
    cin >> x >> y >> ax >> ay >> bx >> by;
    cin >> sx >> sy >> t;
    vec.push_back(make_pair(x , y));
    while(1)
    {
        ll xx , yy , len = vec.size() - 1;
            if(vec[len].fi * 2 + bx < MAXN && vec[len].se * 2 + by < MAXN)
                xx = vec[len].fi * ax + bx , yy = vec[len].se * ay + by;
            else break;
        vec.push_back(make_pair(xx , yy));
    }
    int ans = 0;
    for(int i = 0 ; i < vec.size() ; i ++)
        for(int j = 0 ; j < vec.size() ; j ++)
            if(dist(sx , sy , vec[i].fi , vec[i].se) + dist(vec[i].fi , vec[i].se , vec[j].fi , vec[j].se) <= t)
                ans = max(ans , abs(i - j) + 1);
    cout << ans << ‘\n‘;
    return 0;
}

E. Xenon‘s Attack on the Gangs

题目链接:https://codeforces.com/contest/1293/problem/E

待补

原文地址:https://www.cnblogs.com/StarRoadTang/p/12216456.html

时间: 2024-08-01 05:51:54

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) 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

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

比赛情况 怒切 \(A,B,C,D\),后面 \(E,F\) 两题技术太菜不会做,不知道什么时候可以补起来. 比赛总结 事实证明: 比赛前喝一瓶抗疲劳饮料对比赛状态的进入有显著效果. 比赛有人陪着打对AC题目有显著效果. 说正经的: 不要紧张,也不要太过放松.这样才有利于发挥出真实水平. 下面就开始 喜闻乐见 的题解吧. A 入门题 枚举找到最近的可用楼层即可.用 \(STL\) 里面的 map 判断一个楼层是否可用使用. Code #include<bits/stdc++.h> #defin

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿