#697 div3

http://codeforces.com/contest/1475

A. Odd Divisor

判断2的次幂,是:不能被奇数除;不是:能被奇数除

int n;
cin >> n;
while (n --) {
    ll t;
    cin >> t;
    t &(t - 1) ? puts("YES") : puts("NO");
}

学习:
#697 div3

B. New Year’s Number

暴力:

void solve() {
    int n;
    cin >> n;
    if (n < 2020) {
        puts("NO");
        return;
    }
    for(int i = 0; i < 2000000; i ++) {
        if ((n - i * 2020) < 0) {
        	puts("NO");
            return;
        }
        if ((n - i * 2020) % 2021 == 0) {
            puts("YES");
            return;
        }
    }
}

简单:

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        if ((n % 2020) <= (n / 2020)) puts("YES");
        else puts("NO");
    }
}

C. Ball in Berland *

preparations 准备工作
underway 正在进行
combinations 混合体

ll cnt[200001][2];

void solve() {
	memset(cnt, 0, sizeof(cnt));
	ll a, b, k;
	cin >> a >> b >> k;
	ll ans = (k * (k - 1)) / 2;
	for(ll i = 0; i < k; i ++) {
		int x;
		cin >> x;
		ans -= cnt[x][0] ++;
	} 
	for(ll i = 0; i < k; i ++) {
		int y;
		cin >> y;
		ans -= cnt[y][1] ++;
	}
	cout << ans << endl;
}

D. Cleaning the Phone *

regular 定期的

void solve() {
    ll n, m;
    cin >> n >> m;
    vll a(n), b(n), v1, v2;

    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    for (int i = 0; i < n; i++) {
        if (b[i] == 1) v1.push_back(a[i]);
        else v2.push_back(a[i]);
    }

    sort(v1.rbegin(), v1.rend()); //大数在前小数在后,反向排序
    sort(v2.rbegin(), v2.rend());

    ll sm = 0;
    for (int x : v2) sm += x;

    int r = v2.size(), ans = INT_MAX;
    while (r > 0 && sm - v2[r - 1] >= m) {
        r--;
        sm -= v2[r];
    }

    if (sm >= m) ans = 2 * r;

    for (int l = 0; l < v1.size(); l++) {
        sm += v1[l];
        while (r > 0 && sm - v2[r - 1] >= m) {
            r--;
            sm -= v2[r];
        }

        if (sm >= m) ans = min(ans, (l + 1) + 2 * r);
    }

    if (ans != INT_MAX) cout << ans << endl;
    else cout << -1 << endl;
}
上一篇:设计模式--中介者模式


下一篇:模糊熵、分布熵、近似熵、样本熵理论相关知识与代码实现