Codeforces Round #593 (Div. 2)

Codeforces Round #593 (Div. 2)

A. Stones

  • 思路:水题 先取第一堆中的每一个和先取第二堆中的每一个进行比较就行了
  • AC代码

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int t, a, b, c, cnt, ans;

int main(){
//    freopen("my_in.txt", "r", stdin);
//    freopen("my_out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t -- ){
        ans = 0, cnt = 0;
        cin >> a >> b >> c;
        int x, y, z, tmp;
        x = a, y = b, z = c;
        tmp = min(x, y / 2);
        x -= tmp, y -= tmp * 2;
        cnt += 3 * tmp;
        tmp = min(y, z / 2);
        cnt += 3 * tmp;
        ans = max(ans, cnt);
        cnt = 0;
        x = a, y = b, z = c;
        tmp = min(y, z / 2);
        y -= tmp, z -= tmp * 2;
        cnt += 3 * tmp;
        tmp = min(x, y / 2);
        cnt += 3 * tmp;
        ans = max(ans, cnt);
        cout << ans << "\n";
    }
    return 0;
}

B. Alice and the List of Presents

  • 思路:直接\(\left(2 ^ m - 1\right) ^ n\)
  • AC代码

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll Pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int mod = 1e9 + 7;

ll n, m, ans;

int main(){
//    freopen("my_in.txt", "r", stdin);
//    freopen("my_out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    ans = Pow_mod(Pow_mod(2, m, mod) - 1, n, mod);
    cout << ans << "\n";
    return 0;
}

C. Labs

  • 思路:构造出类似于
    \[
    \begin{matrix}
    1 & 6 & 7\ 2 & 5 & 8\ 3 & 4 & 9\ \end{matrix}
    \]
    即可满足题意
  • AC代码

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 310;

int n, cnt;
int mp[N][N];

int main(){
//    freopen("my_in.txt", "r", stdin);
//    freopen("my_out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i ++ ){
        if (i & 1){
            for (int j = 1; j <= n; j ++ )
                mp[j][i] = ++ cnt;
        }
        else{
            for (int j = n; j >= 1; j -- ){
                mp[j][i] = ++ cnt;
            }
        }
    }
    for (int i = 1; i <= n; i ++ ){
        for (int j = 1; j < n; j ++ )
            cout << mp[i][j] << " ";
        cout << mp[i][n] << "\n";
    }
    return 0;
}

D. Alice and the Doll

  • 思路:暴力模拟即可
  • AC代码

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 1e5 + 10;

ll n, m, k, ans;
set<int> X[N], Y[N];
set<int> XX, YY;

void calc(int x, int y, int d){
    int z;
    set<int>::iterator xx, yy;
    if (d == 1){
        xx = X[x].upper_bound(y), yy = XX.upper_bound(y);
        if (xx == X[x].end())
            z = (*yy) - 1;
        else
            z = min(*xx, *yy) - 1;
        if (z == y)
            return ;
        else{
            ans += z - y;
            YY.insert(x);
            calc(x, z, 2);
        }
    }
    else if (d == 2){
        xx = Y[y].upper_bound(x), yy = YY.upper_bound(x);
        if (xx == Y[y].end())
            z = (*yy) - 1;
        else
            z = min(*xx, *yy) - 1;
        if (z == x)
            return ;
        else{
            ans += z - x;
            XX.insert(y);
            calc(z, y, 3);
        }
    }
    else if (d == 3){
        xx = X[x].lower_bound(y), yy = XX.lower_bound(y);
        yy -- ;
        if (xx == X[x].begin())
            z = (*yy) + 1;
        else{
            xx -- ;
            z = max(*xx, *yy) + 1;
        }
        if (z == y)
            return ;
        else{
            ans += y - z;
            YY.insert(x);
            calc(x, z, 4);
        }
    }
    else if (d == 4){
        xx = Y[y].lower_bound(x), yy = YY.lower_bound(x);
        yy -- ;
        if (xx == Y[y].begin())
            z = (*yy) + 1;
        else{
            xx -- ;
            z = max(*xx, *yy) + 1;
        }
        if (z == x)
            return ;
        else{
            ans += x - z;
            XX.insert(y);
            calc(z, y, 1);
        }
    }
}

int main(){
//    freopen("my_in.txt", "r", stdin);
//    freopen("my_out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ans = 1;
    cin >> n >> m >> k;
    for (int i = 1; i <= k; i ++ ){
        int x, y;
        cin >> x >> y;
        X[x].insert(y);
        Y[y].insert(x);
    }
    XX.insert(0), XX.insert(m + 1);
    YY.insert(0), YY.insert(n + 1);
    calc(1, 1, 1);
    if (ans == n * m - k){
        printf("Yes\n");
        return 0;
    }
    ans = 1;
    XX.clear(), YY.clear();
    XX.insert(0), XX.insert(m + 1);
    YY.insert(0), YY.insert(n + 1);
    calc(1, 1, 2);
    if (ans == n * m - k){
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}

原文地址:https://www.cnblogs.com/Misuchii/p/11729135.html

时间: 2024-10-16 15:08:14

Codeforces Round #593 (Div. 2)的相关文章

Codeforces Round #593 (Div. 2) C. Labs

题目:https://codeforces.com/contest/1236/problem/C 思路:将 n ^ 2 个 lab 平分为 n 个 group group A 和 B 组成的 有序对 ( u , v ) ,u∈A,v∈B 当 u > v 则此有序对有效,求最大值 易发现将1放在group 1,2放在group 2,3放在group 3,......,n放在group n,n+1放在group n,n+2放在group n-2,.......,2n放在group 1,2n+1放在g

Codeforces Round #593 (Div. 2) B. Alice and the List of Presents

Link 题意: \(n\) 种礼物分配给 \(m\) 个盒子 每种礼物有无限个,每个盒子至多拥有同种礼物一个并保证每种礼物至少被分配一次 思路: 求组合数 \(present_1\) 总共 \(2^{m-1}\) 种分法 根据乘法原理 \(n\) 个 \(present\) 共有 \({2^{m-1}}^n\) 种分法 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=1e

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un