码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 980 并查集/模拟贪心最小字典序

时间:2018-05-09 20:54:28      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:type   return   ems   也有   2-2   sign   pac   def   str   

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;
int main()
{
        string a;
        cin >> a;
        int b=0, c=0;
        for (int i = 0; i < a.size(); i++)
        {
                if (a[i] == -)
                {
                        b++;
                }
                else
                {
                        c++;
                }
        }
        //cout<<b<<" "<<c<<endl;
        if (c == 0)
        {
                cout << "YES" << endl;
                return 0;
        }
        if (b % c != 0)
        {
                cout << "NO" << endl;
        }
        else
        {
                cout << "YES" << endl;
        }
        return 0;
}
View Code

B

解:

注意只要是上下对称或者是左右对称就可以使得 1-4 有一条路径的话 2-3 也有相对应的一条路径

剩下的就容易构造了

技术分享图片
/*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;
char ans[5][105];
int main()
{
        int n, k;
        cin >> n >> k;
        for (int i = 1; i <= 4; i++)
        {
                for (int j = 1; j <= n; j++)
                {
                        ans[i][j] = .;
                }
        }
        int sum = (n - 2) * 2;
        if (k > sum)
        {
                cout << "NO" << endl;
                return 0;
        }
        cout << "YES" << endl;
        if (k % 2 == 0)
        {
                int cur = k;
                for (int j = 2; j <= n - 1 && cur; j++)
                {
                        for (int i = 2; i <= 3 && cur; i++)
                        {
                                ans[i][j] = #;
                                cur--;
                        }
                }
        }
        else
        {
                k--;
                ans[2][n / 2 + 1] = #;
                for (int i = 2; i <= 3 && k; i++)
                {
                        for (int j = 2; j <= n / 2 && k; j++)
                        {
                                ans[i][j] = ans[i][n - j + 1] = #;
                                k -= 2;
                        }
                }
        }
        for (int i = 1; i <= 4; i++)
        {
                for (int j = 1; j <= n; j++)
                {
                        cout << ans[i][j];
                }
                cout << endl;
        }
        return 0;
}
View Code

C

解:

可以用并查集维护每个点最小到达的地方 也因为N<=1E5,K<=256 直接暴力模拟也可以

技术分享图片
/*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;
char ans[5][105];
int main()
{
        int n, k;
        cin >> n >> k;
        for (int i = 1; i <= 4; i++)
        {
                for (int j = 1; j <= n; j++)
                {
                        ans[i][j] = .;
                }
        }
        int sum = (n - 2) * 2;
        if (k > sum)
        {
                cout << "NO" << endl;
                return 0;
        }
        cout << "YES" << endl;
        if (k % 2 == 0)
        {
                int cur = k;
                for (int j = 2; j <= n - 1 && cur; j++)
                {
                        for (int i = 2; i <= 3 && cur; i++)
                        {
                                ans[i][j] = #;
                                cur--;
                        }
                }
        }
        else
        {
                k--;
                ans[2][n / 2 + 1] = #;
                for (int i = 2; i <= 3 && k; i++)
                {
                        for (int j = 2; j <= n / 2 && k; j++)
                        {
                                ans[i][j] = ans[i][n - j + 1] = #;
                                k -= 2;
                        }
                }
        }
        for (int i = 1; i <= 4; i++)
        {
                for (int j = 1; j <= n; j++)
                {
                        cout << ans[i][j];
                }
                cout << endl;
        }
        return 0;
}
View Code

D

卡题意

 

E

 

Codeforces 980 并查集/模拟贪心最小字典序

标签:type   return   ems   也有   2-2   sign   pac   def   str   

原文地址:https://www.cnblogs.com/Aragaki/p/9016076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!