Codeforces 976 正方格蛇形走位 二维偏序包含区间 度数图构造 贪心心火牧最大dmg

A

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main()
{
        int n;
        cin >> n;
        string a;
        cin >> a;
        int one = 0;
        int zero = 0;
        for (int i = 0; i < a.size(); i++)
        {
                if (a[i] == '1')
                {
                        one++;
                }
                else
                {
                        zero++;
                }
        }
        while (one >= 2)
        {
                one--;
        }
        for (int i = 1; i <= one; i++)
        {
                cout << 1;
        }
        for (int i = 1; i <= zero; i++)
        {
                cout << 0;
        }
        cout << endl;
}
View Code

B

模拟题 注意细节

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
        ll n, m, k;
        cin >> n >> m >> k;
        ll ansx, ansy;
        if (k <= n - 1)
        {
                cout << k + 1 << " " << 1 << endl;
                return 0;
        }
        if (k <= n + m - 2)
        {
                k -= n - 1;
                cout << n << " " << 1 + k << endl;
                return 0;
        }
        k -= n + m - 2;
        //cout << "k " << k << endl;
        ll duce = k / (m - 1);
        //cout << "duce " << duce << endl;
        int flag = 0;
        if (1LL * duce * (m - 1) == k)
        {
                flag = 1;
        }
        ll cha;
        cha = k - 1LL * duce * (m - 1);
        //cout << "cha " << cha << endl;
        if (1LL * duce * (m - 1) < k)
        {
                cha--;
                duce++;
        }
        //cout << "cha " << cha << endl;
        //cout << "duce " << duce << endl;
        ansy = n - duce;
        if ((duce + flag) % 2)
        {
                ansx = m - cha;
        }
        else
        {
                ansx = 2 + cha;
        }
        cout << ansy << " " << ansx << endl;
}
View Code

C

先按L坐标从小到大排 L相等的时候R也从小到大排

从1到N遍历

假设存在一对i,j符合条件(i<j)且i与j之间的与i不满足与j也不满足 则[i].R>=[j].R 且 [k].R>=[i].R(i<k<j) 这样的话k与j也满足 假设不成立

所以我们知道只要比较相邻的两项就可以了

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
        ll l, r;
        ll index;
} num[300005];
bool operator <(node x, node y)
{
        if (x.l == y.l)
        {
                return x.r < y.r;
        }
        return x.l < y.l;
}
int main()
{
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                cin >> num[i].l >> num[i].r;
                num[i].index = i;
        }
        sort(num + 1, num + 1 + n);
        for (int i = 2; i <= n; i++)
        {
                if (num[i].l == num[i - 1].l)
                {
                        cout << num[i - 1].index << " " << num[i].index << endl;
                        return 0;
                }
                if (num[i].r <= num[i - 1].r)
                {
                        cout << num[i].index << " " << num[i - 1].index << endl;
                        return 0;
                }
        }
        cout << -1 << " " << -1 << endl;
}
View Code

D

给N(N<=300)个数 Di (di<=1000) 要求你构建出一个无向图使得图满足有Dn+1个节点 这些节点的度数形成的集合为给你的数列

 

E

给你N,A,B N个生物 每个生物有HP和DMG两个属性 你可以进行A次操作每次使得一个生物的HP翻倍 B次操作每次使得一个生物的DMG=HP

问你最后这些生物最大的DMG和是多少

贪心 枚举情况思考很容易可以想到A次操作要全部放在一个生物上施展 接下来就是怎么用B和怎么算总DMG的问题了

计算CHA=HP-DMG B操作肯定是用在选择一个生物操作A后的前B大的非负CHA生物

有两种情况

1.当前选择操作A的生物是前B大的  2.当前选择操作A的不是前B大的 

分类讨论就行了

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum = 0;
ll ansernow;
ll anser = 0;
ll add = 0;
struct node
{
        ll hp;
        ll dmg;
        ll cha;
} crea[200005];
bool operator <(node a, node b)
{
        return a.cha > b.cha;
}
int main()
{
        ll n, a, b;
        cin >> n >> a >> b;
        b = min(b, n);
        for (int i = 1; i <= n; i++)
        {
                cin >> crea[i].hp >> crea[i].dmg;
                sum += crea[i].dmg;
                crea[i].cha = crea[i].hp - crea[i].dmg;
        }
        sort(crea + 1, crea + 1 + n);
        if (b == 0)
        {
                cout << sum << endl;
                return 0;
        }
        ll bi = crea[b].cha;
        for (int i = 1; i <= b; i++)
        {
                //cout<<crea[i].cha<<" ";
                if (crea[i].cha > 0)
                {
                        add += crea[i].cha;
                }
        }
        //cout<<endl;
        //cout << "add:" << add << endl;
        anser = add + sum;
        if (a == 0)
        {
                cout << anser << endl;
                return 0;
        }
        ll chanow;
        ll yuan;
        ll cnt;
        for(int i=1;i<=b;i++)
        {
                ansernow=sum+add-max(0LL,crea[i].cha)+max(0LL,crea[i].hp*(1LL<<a)-crea[i].dmg);
                anser=max(anser,ansernow);
        }
        for (int i = b+1; i <= n; i++)
        {
                ansernow=sum+add-max(0LL,crea[b].cha)+max(0LL,crea[i].hp*(1LL<<a)-crea[i].dmg);
                anser=max(anser,ansernow);
        }
        cout << anser << endl;
}
View Code

 

posted @ 2018-05-01 18:21  Aragaki  阅读(169)  评论(0编辑  收藏  举报