2018 秦皇岛CCPC-Wannafly Winter Camp Day5 Div2 题解

A:Cactus Draw

建图后用数组记录点的位置,并不断++,最后依次输出答案。

#include
#include
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 4e3 + 5;
vector e[maxn];
int X[maxn], Y[maxn], h[maxn];
bool vis[maxn];

void dfs(int u, int x, int y, int fa)
{
    X[u] = x, Y[u] = y;
    vis[u] = 0;
    for(int i = 0; i < e[u].size(); ++i)
    {
        int v = e[u][i];
        if(v == fa || vis[v]) continue;
        h[x]++;
        dfs(v, x + 1, h[x], u);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; ++i)
    {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1, 1, 1, 0);
    for(int i = 1; i <= n; ++i)
        cout << X[i] << " " << Y[i] << endl;
    return 0;
}

C:Division

本次签到题,使用优先队列,每次取出来最大的然后除以二并将其再放入队列中即可。

#include
#include
using namespace std;
const int N = 100005;
int a[N];
typedef long long ll;

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    priority_queue q;
    int x;
    for(int i = 0; i < n; ++i)
    {
        scanf("%d", &x);
        q.push(x);
    }
    for(int i = 0; i < k; ++i)
    {
        if(!q.empty())
        {
            int temp = q.top();
            q.pop();
            temp /= 2;
            q.push(temp);
        }
    }
    ll ans = 0;
    while(!q.empty())
    {
        int temp = q.top();
        ans += temp;
        q.pop();
    }
    cout << ans;
    return 0;
}

 

你可能感兴趣的:(2018 秦皇岛CCPC-Wannafly Winter Camp Day5 Div2 题解)