第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)


Xor Transformation

思路:

两种方法,首先是最重要的一个式子:X^K=Y -> K=X^Y,所以先求出这个k,然后普通方法就是二进制枚举k,把最高位的1当做一个数,然后之后的1加起来当做另一个数,由于每次k都会变大,所以先输出小的再输出大的。第二种方法就是先看看k和x的大小,由于k要小于x,所以如果k大于x的话,由于xor一个k和xor一个x再xor一个y是一样的,所以先输出y再输出x即可

二进制:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <sstream>
#define ll long long
#define Endl '\n'
#define endl '\n'

using namespace std;

const int N = 1e5 + 10;
const int M = 1e5 + 10;
const ll mod = 3;
const int INF = 0x3f3f3f3f;

int main()
{
    ll x, y;
    scanf("%lld%lld", &x, &y);

    ll k = x ^ y;
    vector<ll> res;
    ll tmp = 0;

    for (ll i = 63; i >= 0; i -- )
        if(((k >> i) & 1))
        {
            res.push_back((ll)1 << i);
            tmp = k - ((ll)1 << i);
            break;
        }
    
    res.push_back(tmp);
    printf("%lld\n", res.size());
    sort(res.begin(), res.end());
    for (ll i = 0; i < res.size(); i++ )
        printf("%lld ", res[i]);

    return 0;
}

思维:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <sstream>
#define ll long long
#define Endl '\n'
#define endl '\n'
 
using namespace std;
 
const int N = 1e5 + 10;
const int M = 1e5 + 10;
const ll mod = 3;
const int INF = 0x3f3f3f3f;
 
int main()
{
    ll x, y;
    scanf("%lld%lld", &x, &y);
 
    ll k = x ^ y;
    if(k < x){
        cout << 1 << endl;
        cout << k << endl;
    }
    else{
        cout << 2 << endl;
        cout << y << ' ' << x << endl;
    }
 
    return 0;
}

Cook Pancakes!

 

a/b上取整公式:(a+b-1)/b

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 100010, MOD = 1000000007, INF = 0x3f3f3f3f;

int main()
{
    int n, k;
    cin >> n >> k;
    int res = 0;
    if(k >= n)
        res = 2;
    else 
        res = (2 * n + k - 1) / k;
        
    cout << res << endl;

    return 0;
}

Stone Game

 

 

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1000010, M = 100010, MOD = 1000000007, INF = 0x3f3f3f3f;

string g[N];
bool st[N];
int dx[] = {-1, 0}, dy[] = {0, -1};

int main()
{
    IOS;
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    int tmp = min(a1, a2);
    int res = tmp * 2;
    a1 -= tmp;
    a2 -= tmp;

    if(a1)
    {
        res += a1 / 3 * 3;
        a1 %= 3;
        if(a1 == 2)
            res ++;
    } 
    if(a2)
    {
        res += a2 / 3 * 6;
        a2 %= 3;
        if(a2 == 2)
            res += 4;
    }

    cout << res << endl;
    
    return 0;
}

Fight against involution

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 100010, MOD = 1000000007, INF = 0x3f3f3f3f;

string g[N];
bool st[N];
struct Node{
    int l, r;
    bool operator< (const Node& t) const
    {
        if(r == t.r)
            return l > t.l;
        else
            return r < t.r;
    }
} w[N];

int main()
{
    IOS;
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++ )
        cin >> w[i].l >> w[i].r;
    sort(w, w + n);

    LL res = 0, L = 0;
    for (int i = 0; i < n; i ++ ) 
    {
        if(w[i].l > L)//遇到更大的L时,意味着此时R也改变了
            L = w[i].l;
        res += L;
    }

    cout << res << endl;

    return 0;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM