2019中国大学生程序设计竞赛(CCPC)网络选拔赛题解

hdu6702: ^& ^

点此进入

题意: 输入A,B,求使得(A xor C) & (B xor C)最小的最小C。

做法:把二进制的A,B写出来就会发现,要使得这个等式最小,那么C需要在A,B二进制位上所有同为1的变成同为0,可以知道答案就是A & B了,记得开long long。

关于题解
在这里插入图片描述

代码

#include  <map>
#include  <set>
#include  <cmath>
#include  <queue>
#include  <cstdio>
#include  <vector>
#include  <climits>
#include  <cstring>
#include  <cstdlib>
#include  <iostream>
#include  <algorithm>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint register int
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
   
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') {
    if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {
   1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int main() {
   
  int T; scanf("%d", &T);
  LL a, b, c;
  while(T--) {
   
    scanf("%lld %lld", &a, &b);
    c = a & b;
    printf("%lld\n", !c ? 1 : c);
  }
  return 0;
}


hdu6708:Windows Of CCPC

点此进入

题意:找规律,输入一个n,找出对应的图案。

做法:模拟递推,就是将图案复制四份,在左下角的全部取反。

关于题解
在这里插入图片描述

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint register int
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
   
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') {
    if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {
   1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 2010;
const LL Mod = 1e9+7;
const int M = 1e6+10;
char tu[N][N];
int main() {
   
  int T; scanf("%d", &T);
  int n;
  tu[1][1] = tu[1][2] = tu[2][2] = 'C', tu[2][1] = 'P';
  int lx, x;
  _rep(2, 10, i) {
   
     lx = 1<<(i-1); x = 1<<i;
     _rep(1, lx, j) _rep(lx+1, x, k) tu[j][k] = tu[j][k-lx];
     _rep(lx+1, x, j) _rep(1, lx, k) tu[j][k] = tu[j-lx][k] == 'P' ? 'C' : 'P';
     _rep(lx+1, x, j) _rep(lx+1, x, k) tu[j][k] = tu[j-lx][k-lx];
  }
  while(T--) {
   
    scanf("%d", &n);
    x = 1<<n;
    _rep(1, x, i) {
   
      _rep(1, x, j) printf("%c", tu[i][j]);
      puts("");
    }
  }
  return 0;
}

hdu6709:Fishing Master

点此进入

题意:这是一个关于抓鱼和煮鱼的问题,抓鱼和煮鱼都要一定时间,煮鱼的时候可以抓鱼,抓鱼途中不会停止,问按照什么样的顺序抓鱼煮鱼才能使得时间尽可能短。

做法:优先队列,煮鱼的时间是一定要花费的,那么就看煮鱼的时间最多能抓多少条鱼,剩下的时间得重新push回队列,好管理用了一部分煮鱼时间,等了一部分时间的情况。

关于题解
在这里插入图片描述

代码(配上一些测试数据)

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint register int
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string
  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值