2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)


6217 BBP Formula
6218 Bridge
6219 Empty Convex Polygons
6220 Defense of the Ancients
6221 Five-round Show Hand

6222 Heron and His Triangle · 找规律 + 暴力求线性递推式系数

hdu 6222 Heron and His Triangle

暴力求线性递推式系数 · 板子

struct coefficient {
    ll a, b, c, d;

    bool operator<(coefficient x) const {
        int cnt = (!a) + (!b) + (!c) + (!d);
        int cntX = (!x.a) + (!x.b) + (!x.c) + (!x.d);
        return cnt > cntX;
    }
};

// 暴力打表求出前几项 暴力枚举求出线性递推式
// 给出前五项
// 最后打表出的公式也不一定是正确的 存在一定的偶然性 需要先验证一遍
// F[n] = a * F[n - 1] + b * F[n - 2] + c * F[n - 3] +...
void solveFunc() {
    vector<ll> f(10);
    vector<coefficient> res;

    f[0] = 2, f[1] = 4, f[2] = 14, f[3] = 52, f[4] = 194;// 修改这里的系数
    for (int a = -10; a <= 10; a++) {
        for (int b = -10; b <= 10; b++) {
            for (int c = -10; c <= 10; c++) {
                for (int d = -10; d <= 10; d++) {// 留一个常数项
                    ll sum1 = a * f[2] + b * f[1] + c * f[0] + d;
                    ll sum2 = a * f[3] + b * f[2] + c * f[1] + d;
                    // F[n] = a * F[n - 1] + b * F[n - 2] + c * F[n - 3] +...
                    if (sum1 == f[3] && sum2 == f[4]) {
                        res.push_back({a, b, c, d});
                    }
                }
            }
        }
    }
    sort(res.begin(), res.end());
    for (auto func:res) {
        cout << func.a << " " << func.b << " " << func.c << " " << func.d << endl;
    }
}
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        BigInteger lim = new BigInteger("1");
        BigInteger ten = new BigInteger("10");
        for (int i = 1; i <= 30; i++) {
            lim = lim.multiply(ten);
        }
        
        BigInteger[] a = new BigInteger[100];
        BigInteger four = new BigInteger("4");
        a[0] = new BigInteger("2");
        a[1] = new BigInteger("4");
        for (int i = 2; i <= 100; i++) {
            a[i] = new BigInteger("0");
            a[i] = a[i - 1].multiply(four).subtract(a[i - 2]);
            if (a[i].compareTo(lim) > 0) {
                break;
            }
        }

        int t = cin.nextInt();
        BigInteger n;
        for (int i = 1; i <= t; i++) {
            n = cin.nextBigInteger();
            for (int j = 1; j <= 53; j++) {
                if (a[j].compareTo(n) >= 0) {
                    System.out.println(a[j]);
                    break;
                }
            }
        }
    }
}

6223 Infinite Fraction Path
6224 Legends of the Three Kingdoms

6225 Little Boxes

hdu 6225 Little Boxes

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int t = cin.nextInt();
        BigInteger a, b, c, d;
        for (int i = 1; i <= t; i++) {
            a = cin.nextBigInteger();
            b = cin.nextBigInteger();
            c = cin.nextBigInteger();
            d = cin.nextBigInteger();
            System.out.println(a.add(b.add(c.add(d))));
        }
    }
}

6226 New Self-describing Sequence

6227 Rabbits

hdu 6227 Rabbits

#include<bits/stdc++.h>
#define ll long long
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
using namespace std;
int a[510];

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
        int res = 0;
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            if (i > 1)res += (a[i] - a[i - 1] - 1);
        }
        res -= min(a[2] - a[1] - 1, a[n] - a[n - 1] - 1);
        printf("%d\n", res);
    }
    return 0;
}

6228 Tree

6228 Tree

题意:一棵树n个点,k种颜色自己分配,定义 E i E_i Ei 为所有染上第i种颜色的点之间的树链的集合,问所有颜色都经过的边有多少条

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
vector<int> e[N];
int n, k;
int sz[N];
int res = 0;

void dfs(int u, int f) {
    sz[u] = 1;
    for (int v:e[u]) {
        if (v != f) {
            dfs(v, u);
            sz[u] += sz[v];
        }
    }
}

void solve(int u, int f) {
    for (int v:e[u]) {
        if (v != f) {
            if (sz[v] >= k && sz[1] - sz[v] >= k) res++;
            solve(v, u);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int T;
    cin >> T;
    for (int cs = 1; cs <= T; cs++) {

        cin >> n >> k;
        for (int i = 1, u, v; i < n; i++) {
            cin >> u >> v;
            e[u].push_back(v);
            e[v].push_back(u);
        }

        dfs(1, 0);
        solve(1, 0);
        cout << res << endl;

        for (int i = 1; i <= n; i++) {
            e[i].clear();
            sz[i] = 0;
        }
        res = 0;
    }
    return 0;
}

6229 Wandering Robots · 右下角概率之和

6229 Wandering Robots

#include <bits/stdc++.h>
using namespace std;
#define between(x, a, b) (a<=x && x<=b)
typedef long long ll;
typedef pair<int, int> pii;
int n,k;
map<pii, int> mp;
set<pii> st;

int f(int x, int y) {
    int cnt = 0;
    if (between(x - 1, 0, n - 1)) cnt++;
    if (between(x + 1, 0, n - 1)) cnt++;
    if (between(y - 1, 0, n - 1)) cnt++;
    if (between(y + 1, 0, n - 1)) cnt++;
    return cnt;
}

void sub(int x, int y) {
    if (between(x - 1, 0, n - 1)) mp[{x - 1, y}]++;
    if (between(x + 1, 0, n - 1)) mp[{x + 1, y}]++;
    if (between(y - 1, 0, n - 1)) mp[{x, y - 1}]++;
    if (between(y + 1, 0, n - 1)) mp[{x, y + 1}]++;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int T, x, y;
    cin >> T;
    for (int cs = 1; cs <= T; cs++) {
        cout << "Case #" << cs << ": ";
        cin >> n >> k;
        ll mole = 3 * 3 + (n > 1 ? 4 * 2 * (n - 2) + 5 * (n - 2) * (n - 1) / 2 : 0);
        ll deno = 3 * 4 + (n > 1 ? 4 * 4 * (n - 2) + 5 * (n - 2) * (n - 2) : 0);
        while (k--) {
            cin >> x >> y;
            sub(x, y);
            st.insert({x, y});
            int a = f(x, y) + 1;
            deno -= a;
            if (x + y >= n - 1) mole -= a;
        }
        for (auto z:mp) {
            x = z.first.first, y = z.first.second;
            int val = z.second;
            if (st.count({x, y})) continue;

            deno -= val;
            if (x + y >= n - 1) mole -= val;

            int a = f(x, y);
            if (val == a) {//四周包围
                deno--;
                if (x + y >= n - 1) mole--;
            }
        }
        if (mole && deno) {
            ll g = __gcd(mole, deno);
            cout << mole / g << "/" << deno / g << endl;
        } else {
            cout << "0/1" << endl;
        }
        
        mp.clear();
        st.clear();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值