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

    实力眼瞎, D n == 1 ans = 0, 我输出-1 分又没了

    A

    #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;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
     
    int main() {
        IO;
        for (cin >> _; _; --_) {
            cin >> n;
            rep (i, 1, n) cout << i << ' ';
            cout << '
    ';
        }
        return 0;
    }
    

    B

    
    #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;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    int f[105][105];
    char s[105][105];
     
    int main() {
        IO;
        for (cin >> _; _; --_) {
            cin >> n >> m;
            int ans = 0;
            rep (i, 1, n) {
                cin >> s[i] + 1;
                
                if (s[i][m] == 'R') ++ans;
            }
     
            rep (i, 1, m) if (s[n][i] == 'D') ++ans;
            cout << ans << '
    ';
        }
        return 0;
    }
    

    C

    不让你有回去得边, 即边数为 n - 1

    对于 数字n 左右两边, 分别为升序和降序, 则边数必为 n - 1

    #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;
     
    const int N = 1e6 + 5, mod = 1e9  +7;
     
    int n, m, _, k;
    int inv[N] = {0, 1}, a[N] = {1, 1}, b[N] = {1, 1};
     
    int C(int x, int y) {
        if (y == 0 || x == mod) return 1;
        if (x < 0 || y < 0 || y > x) return 0;
        return (ll)a[x] * b[y] % mod * b[x - y] % mod;
    }
     
    void init() {
        rep (i, 2, n) {
            inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
            a[i] = (ll)a[i - 1] * i % mod;
            b[i] = (ll)b[i - 1] * inv[i] % mod;
        }
    }
     
    int main() {
        IO;
        cin >> n; init();
        ll ans = 0;
        rep (i, 1, n) {
            ans = (ans + C(n - 1, i - 1)) % mod;
        }
        ans = (a[n] - ans + mod) % mod;
        cout << ans;
        return 0;
    }
    

    D

    dp

    #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(false);cin.tie(nullptr);cout.tie(nullptr)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
    
    const int N = 1e6 + 5;
    
    int n, m, _, k;
    char s[N];
    int f[N][8], v[N];
    
    bool check(int a, int b) {
        if (n == 2) return (__builtin_popcount(a) + __builtin_popcount(b)) % 2;
        return (__builtin_popcount(a & 3) + __builtin_popcount(b & 3)) % 2
            && (__builtin_popcount(a >> 1) + __builtin_popcount(b >> 1)) % 2; 
    }
    
    int main() {
        IO;
        cin >> n >> m;
        if (n >= 4 &&  m >= 4) { cout << -1; return 0; };
        if (n == 1 || m == 1) { cout << 0; return 0; }
    
        memset(f, 0x3f, sizeof f);
    
        rep (i, 0, n - 1) {
            cin >> s;
            rep (j, 0, m - 1) 
                if (s[j] == '1') v[j] |= 1 << i;
        }
    
        rep (i, 0, m - 1) 
            rep (j, 0, (1 << n) - 1) {
                if (i == 0) f[i][j] = 0;
                else rep (k, 0, (1 << n) - 1) if (check(k, j)) f[i][j] = min(f[i - 1][k], f[i][j]);
                f[i][j] += __builtin_popcount(j ^ v[i]);
                //cout << i << ' ' << j << ' ' << f[i][j] << '
    ';
            }
        
        cout << *min_element(f[m - 1], f[m - 1] + 8);
        return 0;
    }
    
  • 相关阅读:
    从请假日期列表中取得请假起止日期
    存储过程编写经验和优化措施
    安装IE8不能调试VS2003的解决办法
    javascript驗證若干DropDownList是否有選择
    欢迎光临C/S框架网 www.csframework.com
    C#开发框架钢铁贸易进销存系统演示视频
    基于.Net C/S结构系统开发框架V2.2正式发布!
    C#.NET Winform+WebService开发框架完整版本
    C#.Net C/S快速开发框架V2.2版本介绍
    专注C# .Net C/S结构系统开发框架,C/S框架网
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/13468508.html
Copyright © 2011-2022 走看看