2018 Summer ACM cattle off network multi-school training camp (second field) I- car (thinking)

2018 Summer ACM cattle off network multi-school training camp (second field) I- car

Links: https://ac.nowcoder.com/acm/contest/140/I Source: Cattle-off network

Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 131072K, other languages 262144K
64bit the IO the Format: LLD%

Title Description

White Cloud has a square of n*n from (1,1) to (n,n).

White Rabbit wants to know the maximum number of cars that can be put into to ensure that there is a way that allows all cars to perform their entire journey without damage.

(update: all cars should start at the edge of the square and go towards another side, cars which start at the corner can choose either of the two directions)

For example, in a 5*5 square

img

legal

img

illegal(These two cars will collide at (4,4))

img

illegal (One car will go into a damaged grid)

Enter a description:

The first line of input contains two integers n and m(n <= 100000,m <= 100000)For the next m lines,each line contains two integers x,y(1 <= x,y <= n), denoting the grid which is damaged by White Cloud.

Output Description:

Print a number,denoting the maximum number of cars White Rabbit can put into.

Example 1

Entry

copy

2 0

Export

copy

4

Remarks:

Ideas:

Optimal discharge scheme shown above the car.

So we just need to open two arrays, respectively, $ c [i] $ i-th row if there is a pit, $ d [i] $ representing whether the i-th row pit,

Then the determination, if N is an odd number, an intermediate crossroads only put a car, to the attention to detail.

This problem is encountered should calmly analyze the optimal solution, the title to have any effect on the parameters of the optimal solution?

Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {a %= MOD; if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}

inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
map<int, bool> vis;
int n, m;
int getid(int x, int y)
{
    return n * (x - 1) + y;
}
pii a[maxn];
bool hang[maxn];
bool lie[maxn];
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    du2(n, m);
    int x, y;
    repd(i, 1, m) {
        du2(x, y);
        hang[x] = 1;
        lie[y] = 1;
    }
    if (n == 1 && m == 0) {
        return 0 * puts("1");
    } else if (n == 1) {
        return 0 * puts("0");
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (!lie[i]) {
            ans++;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (n & 1) {
            if ((i + i - 1) == n) {
                continue;
            }
        }
        if (!hang[i]) {
            ans++;
        }
    }
    printf("%d\n", ans );


    return 0;
}

inline void getInt(int *p)
{
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    } else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Guess you like

Origin www.cnblogs.com/qieqiemin/p/11802250.html