2021 ICPC網絡賽第一場 The 2021 ICPC Asia Regionals Online Contest (I)


F Land Overseer

思路:

通過樣例不難猜出(a, b - r)這個點,然后開開心心的去交上,結果成功wa了。之后就感覺是不是還有別的情況,通過畫圖可以看出,當b < r時,如果還用上面這種情況,那距離不如中直接走x軸短,所以當b < r時,我們直接讓他走x軸就好了,直接走x軸那距離總共最短就是2a - r

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int T;
    cin >> T;
    for(int i = 1; i <= T; i ++ )
    {
        long long a, b, r;
        cin >> a >> b >> r;
        if(b > r) printf("Case #%d: %.2lf", i, 2.0 * sqrt(a * a + (b - r) * (b - r)) - r);
        else printf("Case #%d: %.2lf", i, 2.0 * a - r);
        if(i != T) cout << endl;
    }
    
    
    return 0;
}

I Neiborhood Search

思路:

好像有好多人理解錯題意了,其實沒有這么復雜,就是判斷輸入的每一位數,看看和給的A相差的絕對值是不是小於r的就可以了,這題關鍵是輸入,因為他沒給你具體要輸入多少個數,所以我們可以邊輸入邊記錄n,或者getline一行后stringstream處理

#include <bits/stdc++.h>

using namespace std;

const int N = 100010;

int s[N];

int main()
{
    int x;
    int n = 0;
    while(cin >> x) s[n ++ ] = x;
    int a = s[n - 2], r = s[n - 1];   
    n -= 2;
    sort(s, s + n, greater<int>());
    for(int i = 0; i < n; i ++ )
        if(abs(s[i] - a) <= r)
            cout << s[i] << ' ';
    
    return 0;
}

K Segment Routing

思路:

給的數據挺多,按題意模擬就好

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

vector<int>p[100010];

int main()
{
    int t;
    cin >> t;
    for(int w = 1; w <= t; w ++ )
    {
        printf("Case #%d: \n",w);
        int n, m;
        cin >> n >> m;
        for(int i = 0; i <= n; i ++ ) p[i].clear();
        for(int i = 1; i <= n; i ++ )
        {
            int k;
            cin >> k;
            while(k--)
            {
                int a;
                cin >> a;
                p[i].push_back(a);
            }
        }
        while(m -- )
        {
            bool flag = false;
            int now = 0;
            
            int a, b;
            cin >> a >> b;
            
            if(a > n) flag = true;
            now = a;
            while(b -- )
            {
                int c;
                cin >> c;
                if(c > p[now].size()) flag = true;
                else now = p[now][c - 1]; 
            }
            if(flag) cout << "Packet Loss";
            else cout << now;
            if(w != t || m != 0) cout << endl;
        }
    }
    return 0;
}

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM