Codeforces 899 1-N两非空集合最小差 末尾最多9对数计算 pair/链表加优先队列最少次数清空

A

/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LLmaxn = 2e18;
const int N = 100005;
int main()
{
        int one = 0;
        int two = 0;
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                int now;
                cin >> now;
                if (now == 1)
                {
                        one++;
                }
                else
                {
                        two++;
                }
        }
        if (one < two)
        {
                cout << one << endl;
        }
        else
        {
                cout << two + (one - two) / 3 << endl;
        }
        return 0;
}
View Code

B

/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LLmaxn = 2e18;
const int N = 100005;
int month1[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month2[13];
int now[100000];
int m[30];
int cnt = 0;
bool ok(int x)
{
        if (x % 400 == 0)
        {
                return true;
        }
        if (x % 4 == 0 && x % 100 > 0)
        {
                return true;
        }
        return false;
}
int main()
{
        for (int i = 1; i <= 12; i++)
        {
                month2[i] = month1[i];
        }
        month2[2] = 29;
        for (int i = 1; i <= 402; i++)
        {
                if (ok(i))
                {
                        for (int j = 1; j <= 12; j++)
                        {
                                now[++cnt] = month2[j];
                        }
                }
                else
                {
                        for (int j = 1; j <= 12; j++)
                        {
                                now[++cnt] = month1[j];
                        }
                }
        }
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                cin >> m[i];
        }
        for (int i = 0; i <= 4010 + 802; i++)
        {
                for (int j = 1; j <= n + 1; j++)
                {
                        if (j == n + 1)
                        {
                                cout << "Yes" << endl;
                                return 0;
                        }
                        if (now[i + j] != m[j])
                        {
                                break;
                        }
                }
        }
        cout << "No" << endl;
}
View Code

C

/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const int N = 1e6 + 5;
vector<int> ans;
int main()
{
        ll n;
        cin >> n;
        ll sum = (n + 1) * n / 2;
        ll want = sum / 2;
        if (sum % 2)
        {
                cout << 1 << endl;
                for (int i = n; i >= 1; i--)
                {
                        if (i <= want)
                        {
                                ans.pb(i);
                                want -= i;
                        }
                }
                cout << ans.size() << " ";
                for (int ch : ans)
                {
                        cout << ch << " ";
                }
                cout << endl;
                return 0;
        }
        else
        {
                cout << 0 << endl;
                for (int i = n; i >= 1; i--)
                {
                        if (i <= want)
                        {
                                ans.pb(i);
                                want -= i;
                        }
                }
                cout << ans.size() << " ";
                for (int ch : ans)
                {
                        cout << ch << " ";
                }
                cout << endl;
                return 0;
        }
}
View Code

D

/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const int N = 1e6 + 5;
vector<int> ans;
int main()
{
        ll now = 5;
        ll aim = 0;
        ll n;
        cin >> n;
        ll anser = 0;
        if (n < 5)
        {
                cout << (n - 1)*n / 2 << endl;
                return 0;
        }
        while (n >= now)
        {
                now *= 10;
                aim++;
        }
        ll remain = 9;
        ll ten = 10;
        for (int i = 1; i <= aim - 1; i++)
        {
                remain *= 10;
                ten *= 10;
                remain += 9;
        }
        //cout << remain << endl;
        //cout << ten << endl;
        ll cnt;
        for (int i = 0; i <= 8; i++)
        {
                cnt = ten * i + remain;
                if (n < (cnt + 1) / 2)
                {
                        break;
                }
                if (n >= cnt)
                {
                        anser += 1LL * cnt / 2;
                }
                else
                {
                        anser += n + 1 - (cnt + 1) / 2;
                }
        }
        cout << anser << endl;
}
View Code

E

/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
int cnt = 0;
int t1, t2;
int pre[N], Next[N], num[N], col[N];
priority_queue<pair<int, int> > que, del;
int main()
{
        int anser = 0;
        int x;
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                cin >> x;
                if (x == col[cnt])
                {
                        num[cnt]++;
                }
                else
                {
                        col[++cnt] = x;
                        num[cnt] = 1;
                }
        }
        for (int i = 1; i <= cnt; i++)
        {
                pre[i] = i - 1, Next[i] = i + 1;
                que.push(mkp(num[i], -i));
        }
        while (cnt)
        {
                while (!del.empty() && que.top() == del.top()) //如果区间已经被合并不存在
                {
                        que.pop();
                        del.pop();
                }
                x = -que.top().second;
                que.pop();
                t1 = pre[x], t2 = Next[x];
                Next[t1] = t2, pre[t2] = t1;
                if (t1 && col[t1] == col[t2])
                {
                        del.push(mkp(num[t2], -t2));
                        del.push(mkp(num[t1], -t1));
                        num[t1] += num[t2];
                        Next[t1] = Next[t2];
                        pre[Next[t2]] = t1;
                        que.push(mkp(num[t1], -t1));
                        cnt--;
                }
                cnt--;
                anser++;
        }
        cout << anser << endl;
}
View Code

 

posted @ 2018-05-14 16:56  Aragaki  阅读(225)  评论(0编辑  收藏  举报