Codeforces 957 水位标记思维题

A

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!
")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
string a;
int anser = 0;
int main()
{
        int n;
        cin >> n;
        cin >> a;
        int len = a.size();
        for (int i = 0; i < len - 1; i++)
        {
                if (a[i] == a[i + 1] && a[i] != '?')
                {
                        cout << "No" << endl;
                        return 0;
                }
        }
        if (a[0] == '?' || a[len - 1] == '?')
        {
                cout << "Yes" << endl;
                return 0;
        }
        for (int i = 1; i < len - 1; i++)
        {
                if (a[i] == '?' && (a[i - 1] == a[i + 1]))
                {
                        cout << "Yes" << endl;
                        return 0;
                }
        }
        for (int i = 0; i < len - 1; i++)
        {
                if (a[i] == a[i + 1] && a[i] == '?')
                {
                        cout << "Yes" << endl;
                        return 0;
                }
        }
        cout << "No" << endl;
}
View Code

B

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!
")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
char f[55][55];
int hang[55];
int main()
{
        int n, m;
        int sum = 0;
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
        {
                scanf("%s", f[i] + 1);
        }
        for (int i = 1; i <= n; i++)
        {
                if (hang[i])
                {
                        continue;
                }
                for (int j = 1; j <= m; j++)
                {
                        if (f[i][j] == '#')
                        {
                                //cout << i << " " << j << endl;
                                for (int k = 1; k <= n; k++)
                                {
                                        if (k == i)
                                        {
                                                continue;
                                        }
                                        if (f[k][j] == '#')
                                        {
                                               // cout << "find" << k << " " << j << endl;
                                                for (int w = 1; w <= m; w++)
                                                {
                                                        if (f[k][w] != f[i][w])
                                                        {
                                                                cout << "No" << endl;
                                                                return 0;
                                                        }
                                                }
                                                hang[k] = 1;
                                        }
                                }
                        }
                }
        }
        cout << "Yes" << endl;
        return 0;
}
View Code

C

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!
")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int num[100005];
int main()
{
        double anser = -1;
        int n, u;
        cin >> n >> u;
        num[n + 1] = INT_MAX;
        for (int i = 1; i <= n; i++)
        {
                scanf("%d", num + i);
        }
        for (int i = 1; i <= n - 2; i++)
        {
                int now = num[i];
                int cha = num[i + 1] - num[i];
                int aim = upper_bound(num + 1, num + n + 2, num[i] + u) - num - 1;
                if (aim - i <= 1 || aim > n)
                {
                        continue;
                }
                //cout << i << " " << aim << endl;
                anser = max(anser, (double)(num[aim] - num[i] - cha) / (double)(num[aim] - num[i]));
        }
        if (anser == -1)
        {
                cout << anser << endl;
        }
        else
        {
                printf("%.10f
", anser);
        }
        return 0;
}
View Code

D

假设在第i次量的时候的总标记数为sum[i] 可知其必定为非递减函数 sum[i]=d[i]+m[i]+1

要使d[i]的总值最小则 要在m[i]+1上面再加数使得 m[i]>=m[i-1]&&m[i+1]-1<=m[i]<=m[i+1]

先从前往后扫一遍满足第一个条件 再从往前扫一遍满足第二个条件

注意要开LL 

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!
")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll num[100005];
int main()
{
        int n;
        cin >> n;
        ll maxn = - 1;
        ll ans = 0;
        for (int i = 1; i <= n; i++)
        {
                scanf("%lld", num + i);
                maxn = max(maxn, num[i]);
        }
        for (int i = 1; i <= n - 1; i++)
        {
                if (num[i + 1] < num[i])
                {
                        ans += num[i] - num[i + 1];
                        num[i + 1] = num[i];
                }
        }
        for (int i = n; i >= 2; i--)
        {
                if (num[i] - num[i - 1] > 1)
                {
                        ans += num[i] - 1 - num[i - 1];
                        num[i - 1] = num[i] - 1;
                }
        }
        cout << ans << endl;
        return 0;
}
View Code
原文地址:https://www.cnblogs.com/Aragaki/p/8647993.html