Codeforces Round #614 (Div. 2)(A~D)

題目鏈接

A. ConneR and the A.R.C. Markland-N(思維)

分析

  • 題意
  1. 有一個n層的樓,每一層都有一個飯店,又給了k個數,表示那些層的飯店是關着的,現在一個人在s層問最少經過多少個樓梯就可以到達一個飯店
  • 思路
  1. 就是從那個人所在的那一層開始,逐漸向外邊樓層,開始枚舉,一旦正枚舉的樓層,沒在k數字中出現,那麼答案就到這一層所需要經過的樓梯數

代碼

#include <bits/stdc++.h>
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define db double
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 2e5 + 10;


int ar[mxn];
map<int, int> mp;

int main()
{
    /* fre(); */
    int T;
    scanf("%d", &T);
    while(T --)
    {
        mp.clear();
        int n, s, k;
        scanf("%d %d %d", &n, &s, &k);
        for(int i = 1; i <= k; i ++)
        {
            scanf("%d", &ar[i]);
            mp[ar[i]] ++;
        }
        for(int i = 0; ; i ++)
        {
            if(s + i <= n && mp[s + i] == 0)
            {
                printf("%d\n", i);
                break;
            }
            if(s - i >= 1 && mp[s - i] == 0) 
            {
                printf("%d\n", i);
                break;
            }
        }
    }

    return 0;
}


B. JOE is on TV!(簡單規律題)

分析

  • 思路
  1. 直接根據題目的意思分別舉例幾個簡單的例子,找一下規律

代碼

#include <bits/stdc++.h>
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define db double
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 2e5 + 10;

int main()
{
    /* fre(); */
    int n;
    scanf("%d", &n);
    db  ans = 0;
    for(int i = 1; i <= n; i ++)
    {
        ans += (1.0/i);
    }
    printf("%f\n", ans);

    return 0;
}


C. NEKO’s Maze Game

分析

  • 題意
  1. 給我們一個2*n的表格,現在一個人要從(1,1)走到(2,n),這個地圖的表格有兩個狀態:可走狀態、不可走狀態(剛開始的時候地圖表格均爲 可行走狀態),給我們q個時刻,第i個時刻(xi,yi)(x_i,y_i)這個表格上狀態發生改變,我們認爲 1個時刻就可以從起點到終點(如果路走的通的話),,對於每個時刻如果能走到終點輸出YES否則NO
  • 思路
  1. 詢問了q個時刻,是否能夠到達終點,當我考慮當前這個時刻能否到達終點是建立在 上一個時刻的地圖的情況 + 這個時刻地圖的改變 的基礎上的,所以我們可以在不斷維護前一刻的基礎上得到當前時刻的答案
  2. 還有我們要注意到所給的地圖是一個 2*n 的地圖,產生無法通過的情況是:在第一行與第二行的存在兩個表格(1,y1)(2,y2)(1,y_1)、(2,y_2)均爲 “不可走狀態”,且y2y1<=1|y_2-y_1|<=1,只要出現了這樣的情況,那個人就無法到達終點了
  3. 利用3. 中分析到的,對於某個時刻我們只改變 某個方格(x,y)(x,y)的狀態,那麼我們要關心的就是與它挨着的三個方格的狀態:(x ^ 1 , y-1 )、( x ^ 1、y)、(x ^ 1,y+1),如果(x,y)方格如果是從“可行走狀態”變爲了“不可行走狀態”的話,我們考慮如果這個三個表格中(x ^ 1 , y-1 )、( x ^ 1、y)、(x ^ 1,y+1)只要存在“不可走狀態”,這個時候(x,y)表格就可以與這三個爲“不可走狀態”的表格中建立“不可通行狀態”,(實際上我們正要維護的就是不可通行的數量);反之如果(x,y)這個表格狀態是從“不可通行”變爲“可通行狀態”的話,我們就要消除對應的不可通行狀態,
  4. 如果某個時刻“不可通行的狀態”的數量爲0的話,這個時候是能到達終點的,輸入yes

代碼

#include <bits/stdc++.h>
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define db double
#define Pir pair<int, int>
#define PIR pair<Pir, Pir>
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 2e5 + 10;
map<PIR, int> mp;
Pir pr;
int mz[3][mxn];

int main()
{
    /* fre(); */
    int n, q;
    scanf("%d %d", &n, &q);
    int sum = 0;
    while(q --)
    {
        scanf("%d %d", &pr.fi, &pr.se);
        mz[pr.fi][pr.se] = mz[pr.fi][pr.se] ^ 1;
        for(int j = pr.se - 1; j <= pr.se + 1; j ++)
        {
            int i = (pr.fi == 1 ? 2 : 1);
            if(i < 1 || j < 1 || i > 2 || j > n) continue;
            if(mz[pr.fi][pr.se])
            {
                if(mz[i][j])
                    sum ++;
            }
            else
            {
                if(mz[i][j])
                    sum --;
            }

        }

        if(sum)
            printf("No\n");
        else
            printf("Yes\n");
    }

    return 0;
}

D. Aroma’s Search(模擬?暴力?)

分析

  • 題意
  1. 這個一個二位座標系內,給我們第一個金幣的位置(x0,y0)(x_0,y_0),之後又給我們了其它金幣位置的地推表達式:(axxi1+bx,   ayyi1+by)(a_x*x_{i-1}+b_x,~~~a_y*y_{i-1}+b_y),之後又給我我們玩家的初始位置(xs,ys)(x_s,y_s), 問玩家只能走t個單位距離的情況下最多能夠獲得多少個金幣?
  • 思路
  1. 這一題的突破口就在數範圍:1<=y0,y0<=1e16   2<=ax,ay<=100  0<=bx,by<=1e16t<=1e161<=y_0,y0<=1e16~~、~2<=a_x,a_y<=100~~、0<=b_x,b_y<=1e16、t<=1e16,雖然給的數據範圍很大但是,由於金幣的位置是遞推出來的,所以在整個二位座標系中再符合題意的情況下不會有多餘63個金幣出現,而且喫金幣肯定是 喫一個連續的一段中的金幣,所要我們暴力枚舉所有 連續段 情況,找出其中最優答案即可。。。

  2. 這道題雖然按 2. 這一步中敘述的很簡單,但是我們不免疑惑是否存在一種這樣的情況:就是如果 玩家 先回去喫之前距離比較近的金幣,最後如果喫完了之前比較近的金幣之後,在回過頭來喫後們的金幣間隔比較的大,耗費的距離比較的大的金幣呢??這種情況是存在的,不過我們比較 我們利用暴力枚舉段的方法所走的最優路程a 與我們考慮折返情況的路程b 進行比較的話 發現 a路程 更短—>具體原因:通過對所走的路程構造“三角形兩邊之和一定大於第三邊”,我們講a與b路程重複的部分去掉髮現,b路程剩下兩條邊與a路程只剩下一條邊可以構成三角形,顯然a路程剩下的那條邊一定小魚b路程剩下的兩條邊的距離之和,(可能這裏沒說清楚,但是主要的 考慮思路就在這裏,自己多想想這點的證明),,,所以2.中敘述的方法是沒問題的

代碼

#include <bits/stdc++.h>
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long 
#define db double
#define Pir pair<int, int>
#define PIR pair<Pir, Pir>
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 2e3 + 10;
const ull lim = 1e17; //主要這裏必須是1e17,不能是1e16,自己想想吧
ll x[mxn], y[mxn];


int main()
{
    /* fre(); */
    ll ax, ay, bx, by; 
    scanf("%lld %lld %lld %lld %lld %lld", &x[0], &y[0], &ax, &ay, &bx, &by);
    ll sx, sy, t;
    scanf("%lld %lld %lld", &sx, &sy, &t);

    int n = 1;
    while(true)
    {
        x[n] = x[n - 1] * ax + bx;
        y[n] = y[n - 1] * ay + by;
        if(x[n] > lim || y[n] >  lim) break;
        n ++;
    }

    ll ans = 0;
    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < n; j ++)
        {
            ll t1 = abs(x[i] - sx) + abs(y[i] - sy);
            ll t2 = abs(x[j] - sx) + abs(y[j] - sy);
            ll t3 = min(t1, t2) + abs(x[i] - x[j]) + abs(y[i] - y[j]);
            if(t3 <= t)
                ans = max(ans, j - i + 1LL);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章