codeforces -1269D - Domino for Young(思维)

题目大意:

给你n列格子,给出每列的高度(非递增),求最多放多少个1×2的格子(横着竖着都行)

题目思路:

假如给了这样一个序列

 

 

然后我们对每一个格子都标记,使得他和相邻的数字都不同

我每放置一个1*2的物品,肯定是0和1各占用一个

只需要求0和1的出现次数的最小值的就是答案

可以联想一下二分图的行列模型?

CODE:

// Problem: D. Domino for Young
// Contest: Codeforces - Codeforces Round #609 (Div. 2)
// URL: https://codeforces.com/problemset/problem/1269/D
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 7;
const ll mod = 1e9 + 7;

#define pb push_back
#define mst(x, a) memset(x, a, sizeof(x))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define dep(i, a, b) for (int i = (a); i >= (b); --i)

inline ll read() {
  ll x = 0;
  bool f = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch) f |= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}

void out(ll x) {
  int stackk[20];
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  int top = 0;
  while (x) stackk[++top] = x % 10, x /= 10;
  while (top) putchar(stackk[top--] + '0');
}
ll qpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
ll n;
int main() { 
    n=read();
    ll one =0,zero =0 ;
    for(int i=1 ;i<=n ;i++)
    {
        int x = read();
        if(i%2)
        {
            one+=x/2;
            zero+=(x+1)/2;
        }
        else
        {
            zero+=x/2;
            one+=(x+1)/2;
        }
    }
    
    out(min(zero,one));
    return 0; 
}
/*


*/
View Code

 

posted @ 2021-04-26 21:50  UpMing  阅读(57)  评论(0编辑  收藏  举报