At grand 024

A

/* 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
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
using namespace std;
typedef long long ll;
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
const long long mod = 1e9 + 7;
const int N = 1e5 + 5;
int main()
{
        ll a, b, c, k;
        cin >> a >> b >> c >> k;
        if (k % 2 == 1)
        {
                cout << b - a << endl;
        }
        else
        {
                cout << a - b << endl;
        }
        return 0;
}
View Code

B

只要算出最长 数字连续子序列就可以了

/* 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
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
using namespace std;
typedef long long ll;
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
int n;
int num[N];
int aim[N];
int main()
{
        read(n);
        int now;
        for (int i = 1; i <= n; i++)
        {
                read(now);
                num[now] = i;
        }
        int ans = 1;
        int ansmaxn = 1;
        for (int i = 2; i <= n; i++)
        {
                if (num[i] > num[i - 1])
                {
                        ans++;
                }
                else
                {
                        ans = 1;
                }
                ansmaxn = max(ansmaxn, ans);
        }
        cout << n - ansmaxn << endl;
        return 0;
}
View Code

C

给你两个数组A,B  A全为0  B是给定的N个数

一次操作可以使得Ai(2<=i<=N) 变为 Ai-1+1

解:

首先排除不合法的情况: ①.当A0不为0的时候 ②.当前面的数减后面的数大于1的时候

/* 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
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
using namespace std;
typedef long long ll;
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
int n;
ll num[N];
int main()
{
        read(n);
        for (int i = 1; i <= n; i++)
        {
                cin >> num[i];
        }
        if (num[1] != 0)
        {
                cout << -1 << endl;
                return 0;
        }
        for (int i = 2; i <= n; i++)
        {
                if (num[i] - num[i - 1] > 1)
                {
                        cout << -1 << endl;
                        return 0;
                }
        }
        ll anser = 0;
        for (int i = 2; i <= n; i++)
        {
                if (num[i] == num[i - 1] + 1)
                {
                        anser++;
                }
                else
                {
                        anser += num[i];
                }
        }
        cout << anser << endl;
        return 0;
}
View Code

D

posted @ 2018-05-21 22:06  Aragaki  阅读(133)  评论(0编辑  收藏  举报