zoukankan      html  css  js  c++  java
  • Codeforces Round #662 (Div. 2)

    A

    题看不懂,猜答案

    多试试, A题嘛, 总能猜出来(没了100分), 实在是看不懂题

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(0); cin.tie(0);
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
    typedef unsigned long long ull;
    typedef unsigned int uint;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    int a[N], b[N];
     
    int main() {
    	IO;
    	for (cin >> _; _; --_) {
    		cin >> n;
    		cout << n / 2 + 1 << '
    ';
    	}
    	return 0;
    }
    

    B

    wa 1发, 细节没处理好

    每次是弹操作, 我们直接根据改变之后长为 i 板子的数量, 维护两个值就好了

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(0); cin.tie(0);
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
    typedef unsigned long long ull;
    typedef unsigned int uint;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    int a[N], x, y;
    char s[5];
     
    int main() {
        IO;
    	cin >> n;
    	rep (i, 1, n) cin >> m, ++a[m];
    	rep (i, 1, 1e5) {
    		x += a[i] / 4;
    		y += a[i] % 4 / 2;
    	}
     
    	cin >> n;
    	rep (i, 1, n) {
    		cin >> s >> m;
    		if (s[0] == '+') {
    			++a[m];
    			if(a[m] % 4 == 0) ++x, --y;
    			else if (a[m] % 4 == 2) ++y;
    		}
    		else {
    			--a[m];
    			if (a[m] % 4 == 3) --x, ++y;
    			else if (a[m] % 4 == 1) --y;
    		}
     
    		if (x && (x > 1 || y >= 2)) cout << "YES
    ";
    		else cout << "NO
    ";
    	}
        return 0;
    }
    

    C

    首先考虑种类最多的馅饼, 占据 a 个位置, 那么之间的间隙最大值为 x = (n - a) / (a - 1),

    因为是向下取整, 那么我们记下余数(一会用) y = n - a - (a - 1) * x

    考虑其他的, 全是数量小于a的, 那么答案必是 a

    如果存在 b 种馅饼数量和 a 相等
    b <= y, 毫无疑问错位满足 x, 答案是 x
    b > y, 明显 x 大了, --x, 循环重判(y就变大了)

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(0); cin.tie(0);
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
    typedef unsigned long long ull;
    typedef unsigned int uint;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    int a[N], b[N];
     
    int main() {
    	IO;
    	for (cin >> _; _; --_) {
    		cin >> n;
    		memset(b, 0, sizeof b);
    		rep(i, 1, n) cin >> a[i], ++b[a[i]];
    		sort(b + 1, b + 1 + n, greater<int>());
    		int x = (n - b[1]) / (b[1] - 1), y = n - b[1] - (b[1] - 1) * x;
    		while (true) {
    			int t = 2;
    			while (t <= n && b[t] == b[t - 1] && y) --y, ++t;
    			if (t > n || b[t] != b[t - 1]) { cout << x << '
    '; break; }
    			y = n - b[1] - (b[1] - 1) * (--x);
    		}
    	}
    	return 0;
    }
    

    D

    拼接就完事了, l是left, r是right, u是up, d是down

    add: 看了题解, 真的服气, 直接dp一次即可, 我这浪费时间了,tcl

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(0); cin.tie(0);
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
    typedef unsigned long long ull;
    typedef unsigned int uint;
     
    const int N = 2005;
     
    int n, m, _, k;
    char s[N][N];
    int l[N][N], r[N][N], u[N][N], d[N][N];
    int lu[N][N], ru[N][N], ld[N][N], rd[N][N];
     
    int main() {
    	IO;
    	cin >> n >> m;
    	ll ans = 0;
    	rep(i, 1, n) {
    		cin >> s[i] + 1;
     
    		rep(j, 1, m) {
    			if (s[i][j] == s[i][j - 1]) l[i][j] = l[i][j - 1] + 1;
    			else l[i][j] = 1;
     
    			if (s[i][j] == s[i - 1][j]) u[i][j] = u[i - 1][j] + 1;
    			else u[i][j] = 1;
     
    			if (s[i][j] == s[i - 1][j - 1]) lu[i][j] = min(min(u[i][j], l[i][j]), lu[i - 1][j - 1] + 2);
    			else lu[i][j] = max(1, min(2, min(u[i][j], l[i][j])));
    		}
    	}
     
    	per(i, n, 1) {
    		per(j, m, 1) {
    			if (s[i][j] == s[i][j + 1]) r[i][j] = r[i][j + 1] + 1;
    			else r[i][j] = 1;
     
    			if (s[i][j] == s[i + 1][j]) d[i][j] = d[i + 1][j] + 1;
    			else d[i][j] = 1;
     
    			if (s[i][j] == s[i + 1][j + 1]) rd[i][j] = min(min(r[i][j], d[i][j]), rd[i + 1][j + 1] + 2);
    			else rd[i][j] = max(1, min(2, min(r[i][j], d[i][j])));
    		}
     
    		rep(j, 1, m) {
    			if (s[i][j] == s[i + 1][j - 1]) ld[i][j] = min(min(l[i][j], d[i][j]), ld[i + 1][j - 1] + 2);
    			else ld[i][j] = max(1, min(2, min(l[i][j], d[i][j])));
    		}
    	}
     
    	rep(i, 1, n) {
    		per(j, m, 1) {
    			if (s[i][j] == s[i - 1][j + 1]) ru[i][j] = min(min(r[i][j], u[i][j]), ru[i - 1][j + 1] + 2);
    			else ru[i][j] = max(1, min(2, min(r[i][j], u[i][j])));
     
    			int c = min(min(lu[i][j], ru[i][j]), min(ld[i][j], rd[i][j]));
    			ans += c;
    		}
    	}
     
    	cout << ans;
    	return 0;
    }
    

    E1

    时间不够了, 没调出来, wa在test6

    暴力思路, map记忆化搜索, 在截取串的时候, 用两个for, 把删去的第i个字母隔开就行了 O(len(s))

    明天试试能不能暴力出来吧

  • 相关阅读:
    金蝶软件常用基础SQL数据表
    改变cxgrid行字体颜色
    C#默认修饰符
    const和static
    怎么写动态游标
    Report Machine支持导出PDF
    C1TrueDBGrid注册码
    免费在线思维导图工具Mindv V1.1.0发布
    支持中文输入的免费的Silverlight Richtextbox
    云计算浅谈之一:云计算介绍
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/13456091.html
Copyright © 2011-2022 走看看