2018 여름 ACM 가축 오프 네트워크 용 멀티 학교 교육 캠프 (두 번째 필드) I- 자동차 (생각)

2018 여름 ACM 가축 오프 네트워크 용 멀티 학교 교육 캠프 (두 번째 필드) I- 자동차

링크 : https://ac.nowcoder.com/acm/contest/140/I 출처 : 가축 오프 네트워크

시간 제한 : C / C ++ 일초, 이초 언어, 다른
공간의 제한 : C / C ++ 131072K, 다른 언어 262144K의
64 비트 IO 형식 : LLD의 %

제목 설명

화이트 클라우드 (N, N-)에 (1,1)에서 n 개의 * n의 사각형이 있습니다.

흰 토끼는 모든 차량 손상없이 전체 여정을 수행 할 수있는 방법이 있는지 확인하기 위해 투입 될 수있다 자동차의 최대 수를 알고 싶어한다.

(갱신 : 모든 차량이 광장의 가장자리에서 시작해야하며, 두 방향 중 하나를 선택할 수 있습니다, 다른쪽으로 코너에서 시작 차를 이동)

예를 들어, 5 * 5 광장

IMG

적법한

IMG

불법 (이 두 차량에 충돌한다 (4,4))

IMG

불법 (한 차는 손상 그리드로 이동합니다)

설명을 입력합니다 :

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.

출력 설명 :

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

예 1

기입

복사

2 0

수출

복사

4

비고 :

아이디어 :

차 위에 표시된 최적의 방전 방식.

그래서 우리가 두 개의 배열을 열어야 각각 $ C의 [I] $ i 행 피트, $ d 개 [I] $ 나타내는있을 경우, i 번째 행 피트 여부,

N이 홀수 인 경우, 상기 결정은, 중간기로 만 세부 사항에주의 차를 넣어.

침착하게 최적의 솔루션을 분석해야 발생이 문제는, 제목은 최적의 솔루션의 매개 변수에 어떤 효과가?

코드 :

#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';
        }
    }
}



추천

출처www.cnblogs.com/qieqiemin/p/11802250.html