8-13 下午测试

· · 个人记录

kesesesesese!!今天考的真的不是很好啊啊啊(╯▔皿▔)╯

B2102

错误原因

正确思路

#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int main()
{
    for(int i = 1; i <= 5; i++)
    {
        for(int j = 1; j <= 5; j++)
        {
            cin >> a[i][j];
        }
    }
    bool flag = false;
    for(int i = 1; i <= 5; i++)
    {
        for(int j = 1; j <= 5; j++)
        {
            int maxn = 0, minn = 100000005;
            for(int k = 1; k <= 5; k++)
            {
                maxn = max(maxn, a[i][k]);
                minn = min(minn, a[k][j]);
            }
            if(maxn == a[i][j] && minn == a[i][j])
            {
                flag = true;
                cout << i << " " << j << " " << a[i][j] << "\n";
            }
        }
    }
    if(flag == false) cout << "not found";
    return 0;
}

P1897

错误原因

正确思路

#include<bits/stdc++.h>
using namespace std;
long long a[1000005];
int main()
{
    long long n, cnt = 0, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cnt = 1;
    sort(a + 1, a + 1 + n);
    while(cnt != n + 1)
    {
        int c = a[cnt] - a[cnt - 1];
        if(c == 0) ans += 1;
        else ans += (c * 6 + 6);
        cnt++;
    }
    ans += a[cnt - 1] * 4; 
    cout << ans << endl;
    return 0;
}

P1454

错误原因

正确思路

-先寻找联通块数量,这里的连通块定义与其他的不同. 这里定义为曼哈顿距离不超过2的都属于一个联通块。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int nx[15] = {0, 1, -1, 0, 0, 2, -2, 0, 0, 1, -1, 1, -1};
const int ny[15] = {0, 0, 0, 1, -1, 0, 0, 2, -2, -1, 1, 1, -1}; 
char a[1005][1005];
void dfs(int x, int y)
{
    if(x < 1 || x > n || y < 1 || y > m || a[x][y] != '#') return;
    a[x][y] = '-';
    for(int i = 1; i <= 12; i++)dfs(x + nx[i], y + ny[i]);
    return ;
}
int main()
{
    int n, m, ans = 0;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) 
    {
        for(int j = 1; j <= m; j++) cin >> a[i][j];
    } 
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if (a[i][j] == '#')
            {
                ans++;
                dfs(i, j);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

P9050

错误原因

正确思路

正确代码

#include <bits/stdc++.h>
using namespace std;;
long long a[500005], b[500005], n, ans;
bool check(long long x)
{
    long long ans = a[x];
    for(int i = 1; i < x; i++)
    {
        if(a[i] < ans) ans += a[i];
        else return 0;
    } 
    for(int i = x + 1; i <= n; i++)
    {
        if(ans > a[i]) ans += a[i];
        else return 0;
    }
    return 1;
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        b[i] = a[i];
    } 
    sort(a + 1, a + n + 1);
    long long l = 1, r = n + 1, mid;
    while(l < r)
    {
        mid = (l + r) / 2;
        if(check(mid)) r = mid;
        else l = mid + 1;
    }
    if(!check(l))
    {
        for(int i = 1; i <= n; i++) cout << "N";
        return 0;
    }
    for(int i = 1; i <= n; i++)
    {
        if(b[i] >= a[l]) cout << "T";
        else cout << "N";
    }
    return 0;
}