Test47普转提考试总结
Claire0630 · · 题解
Test47普转提考试总结
Data
Score:190 = 100 + 0 + 60 + 10 + 20
Rank: (Data damaged and lost)
Preface
好吧好吧,状态挺差的
我也没啥好说的
T1直接过
T2贪心我是真贪不动啊(感觉需要求救了,我的贪心烂成一坨了,给我100块钱我都不要的感觉)
T3基本是原题,但还是没A掉
T4太猎奇的大模拟DP了
T5是真的看不出来图论
好吧好吧
Statements
A. 十字斩
题目描述
小 Z 是某大学新生,在迎新晚会上,老师向大家介绍了十字斩活动。
活动场地可以视为一个具有坐标轴的无限平面直角坐标系。坐标系中有许多气球,气球的坐标可以用两整数对刻画,而学生们的目标是用十字斩来破坏最多的气球。
十字斩可以形象的刻画为相互垂直的两条直线,并且每条直线与坐标轴的夹角均为 45°。使用十字斩后,两条直线上的气球均被破坏。
小 Z 想要赢得这场活动的胜利,走向大学人生巅峰。于是他选了若干个位置,想问你如果他站在这些位置释放十字斩,他能破坏多少气球。
输入格式
第一行两个正整数
接下来
接下来
输出格式
然后我们就用map存一下就好了
Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
template <typename T> inline void read(T &x){
x = 0;
LL f = 1;
char c = getchar();
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
template <typename T> inline void print(T x){
if(x < 0) x = -x,putchar('-');
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
const int N = 1e5 + 11;
LL n,m;
map<LL,LL> mp_up,mp_down;
map<PLL,bool> est;
int main(){
// freopen("cross.in","r",stdin);
// freopen("cross.out","w",stdout);
read(n);read(m);
for(LL i=1;i<=n;i++){
LL x,y;
read(x);read(y);
mp_up[y - x] ++;
mp_down[y + x] ++;
est[{x,y}] = 1;
}
while(m --){
LL x,y;
read(x);read(y);
print(mp_up[y - x] + mp_down[y + x] - (est[{x,y}] == 1 ? 1 : 0));
putchar('\n');
}
return 0;
}
B. 大富翁
题目描述
新生们为了促进感情,准备去玩桌游,他们选择了大富翁游戏。大富翁的胜利目标是为了收取更多的租金,获得更多的钱。
地图上有
购买房屋和装修房屋都需要时间,第
输入格式
第一行两个整数
接下来
输出格式
输出一行一个整数,代表小 Z 能获得的最大金币数。
输入输出样例
输入:
2 10000000000
2 1
1 2
输出:
399999999861
Solution
我们使用贪心思想
我们发现,其实对于每个房屋都只有两种选择,一种是建完之后立马装修,或者是建完之后就摆在那里先不装修
我们又需要在更少的时间内将金币数达到最大才可取得最大收益
因此我们整个流程的时间顺序一定是从小到大的
我们使用优先队列动态处理这个问题
定义优先级为
前者表示先买房但不着急装修,后者表示买完房立刻装修,考虑这两段时间的最小值,才是我们上面需要的最大收益
然后按优先级从小到大处理,在中途计算贡献即可
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
template <typename T> inline void read(T &x){
x = 0;
LL f = 1;
char c = getchar();
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
template <typename T> inline void print(T x){
if(x < 0) x = -x,putchar('-');
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
inline void sprint(const string s){
for(auto x : s) putchar(x);
return;
}
const int N = 6e5 + 11,M = 20;
LL n,m,cur,tot,ans;
__attribute__((always_inline)) void add(LL tim){
ans += tim * tot;
cur += tim;
tot ++;
return;
}
int main(){
// freopen("rich.in","r",stdin);
// freopen("rich.out","w",stdout);
auto cmp = [](const PLL &x,const PLL &y){
LL tmp1 = min(x.first * 2,x.first + x.second);
LL tmp2 = min(y.first * 2,y.first + y.second);
if(tmp1 > tmp2) return 1;
return 0;
};
priority_queue<PLL,vector<PLL>,decltype(cmp)> pq(cmp);
read(n);read(m);
for(LL i=1;i<=n;i++){
LL x,y;
read(x);read(y);
pq.push((PLL){x,y});
}
while(pq.size()){
PLL t = pq.top();
pq.pop();
add(t.first);
if(t.second != 1e18) pq.push((PLL){t.second,1e18});
}
if(cur < m) ans += (m - cur) * tot;
print(ans);
return 0;
}
C. 联谊舞会
题目描述
一年一度的联谊舞会开始了,每位学生都能交到自己心仪的朋友。
为了吸引同学参加,主办方在今年想出了交友的新办法:主办方在舞厅中间画出了一个分界线,分界线的上方和下方都有一些从左往右的“站点”,每位同学都需要从一个分界线上方的“站点”跑到一个分界线下方的“站点”,如果两个同学的跑步路线相交,那么他们便交友成功。
输入格式
第一行一个正整数
接下来一行
接下来一行
输出格式
输出一个整数,代表最大朋友圈的大小。
输入输出样例
3
1 2 3
3 2 1
输出:
3
Solution
我们发现这道题其实和远古时期的CWOI上一道题很像
其实确实差不多
只不过那个是尽量不交叉,这个是尽量多交叉
注意,此题需要你在
否则我们二分查找到小于
复杂度为
Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
template <typename T> inline void read(T &x){
x = 0;
LL f = 1;
char c = getchar();
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
template <typename T> inline void print(T x){
if(x < 0) x = -x,putchar('-');
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
const int N = 1e5 + 11;
struct node{
int s,t,id;
}g[N];
int dp[N];
int n;
unordered_map<int,int> mp;
int main(){
// freopen("dance.in","r",stdin);
// freopen("dance.out","w",stdout);
read(n);
for(int i=1;i<=n;i++){
read(g[i].s);
mp[g[i].s] = i;
}
for(int i=1;i<=n;i++){
read(g[i].t);
g[i].id = mp[g[i].t];
}
int cur = 0;
dp[0] = 0x3f3f3f3f;
for(int i=1;i<=n;i++){
if(g[i].id < dp[cur]){
cur ++;
dp[cur] = g[i].id;
}else{
int l = 0,r = n,ans = 0;
while(l <= r){
int mid = l + r >> 1;
if(dp[mid] > g[i].id){
ans = mid;
l = mid + 1;
}else r = mid - 1;
}
dp[ans + 1] = g[i].id;
}
}
print(cur);
}
D. 唬牌游戏
题目描述
近些天,一款名为唬牌的游戏风靡全校,游戏规则如下:
所需游戏道具是若干张扑克牌,此时每张牌都具有一个花色。
一共两名玩家参赛,游戏共两局。在第一个回合中,玩家 A 将若干张相同花色的扑克牌扣置(此时玩家 B 不知道玩家 A 扣置的是什么花色),并声称一种花色,玩家 B 则需要猜测玩家 A 所扣置的牌是否与其声称花色相同,猜对则 B 得一分。
输入格式
第一行四个整数,代表扑克牌中方片、草花、红桃、黑桃牌的张数。
第二行输入一个整数
接下来
输出格式
输出
输入输出样例1
输入:
1 1 1 1
2
D 1 T
D 1 F
输出:
F
NG
ERROR
Solution
其实可以直接大模拟一波
只要你愿意
但其实我们是需要一个dp数组来表示当前状态是否可用
我们设
我们在进行前
-
如果当前情况为T
-
如果是
x 张方片,我们直接-
dp_{i,j,k,l,q} |= dp_{i - 1,j - x,k,l,q}
-
-
以此类推......
-
-
如果当前情况为F
-
如果是
x 张方片,我们直接-
dp_{i,j,k,l,q} |= dp_{i - 1,j,k - x,l,q} -
dp_{i,j,k,l,q} |= dp_{i - 1,j,k,l - x,q} -
dp_{i,j,k,l,q} |= dp_{i - 1,j,k,l,q - x}
-
-
以此类推......
-
然后我们就根据
我们在查询时枚举每一类牌还剩余的张数,在保证这种情况合法的前提下(如果一直不合法就是ERROR)
我们尝试给出这
x 张牌,如果给出之后还剩余就不可能是F在确定只有这一种牌给出之后还有剩余才是T
不然就是NG
我们就分讨完成
Tips:
1.注意内存不够,我们需要滚动数组优化
2.在枚举时不需要枚举四种牌,三种就够了,因为我们枚举给出的牌数量是固定的,可以枚举后计算最后一种牌的数量
Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
template <typename T> inline void read(T &x){
x = 0;
LL f = 1;
char c = getchar();
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
template <typename T> inline void print(T x){
if(x < 0) x = -x,putchar('-');
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
inline void sprint(const string s){
for(auto x : s) putchar(x);
}
const int N = 85;
int dmx,cmx,hmx,smx,n,m,sum;
int dp[2][N][N][N][N];
int main(){
// freopen("game.in","r",stdin);
// freopen("game.out","w",stdout);
read(dmx);read(cmx);read(hmx);read(smx);
read(n);
dp[0][0][0][0][0] = 1;
for(int i=1;i<=n;i++){
char c,idn;
int x;
cin>>c;
read(x);
cin>>idn;
sum += x;
for(int j=0;j<=dmx;j++){
for(int k=0;k<=cmx;k++){
for(int l=0;l<=hmx;l++){
int q = sum - j - k - l;
if(q < 0 || q > smx) continue;
dp[i & 1][j][k][l][q] = 0;
}
}
}
for(int j=0;j<=dmx;j++){
for(int k=0;k<=cmx;k++){
for(int l=0;l<=hmx;l++){
int q = sum - j - k - l;
if(q < 0 || q > smx) continue;
if(((idn == 'T' && c == 'D') || (idn == 'F' && c != 'D')) && j >= x) dp[i & 1][j][k][l][q] |= dp[(i & 1) ^ 1][j - x][k][l][q];
if(((idn == 'T' && c == 'C') || (idn == 'F' && c != 'C')) && k >= x) dp[i & 1][j][k][l][q] |= dp[(i & 1) ^ 1][j][k - x][l][q];
if(((idn == 'T' && c == 'H') || (idn == 'F' && c != 'H')) && l >= x) dp[i & 1][j][k][l][q] |= dp[(i & 1) ^ 1][j][k][l - x][q];
if(((idn == 'T' && c == 'S') || (idn == 'F' && c != 'S')) && q >= x) dp[i & 1][j][k][l][q] |= dp[(i & 1) ^ 1][j][k][l][q - x];
}
}
}
}
read(m);
while(m --){
char c;
int x;
cin>>c;
read(x);
bool malf = 1,fls = 1,tru = 1,ucr = 0;
for(int i=0;i<=dmx;i++){
for(int j=0;j<=cmx;j++){
for(int k=0;k<=hmx;k++){
int l = sum - i - j - k;
if(l < 0 || l > smx) continue;
if((dmx - x) < i && (cmx - x) < j && (hmx - x) < k && (smx - x) < l) continue;
if(dp[n & 1][i][j][k][l] == 1){
malf = 0;
if(c == 'D'){
if((dmx - x) >= i) fls = 0;
if((dmx - x) >= i && (cmx - x) < j && (hmx - x) < k && (smx - x) < l) ucr = 1;
else tru = 0;
}
else if(c == 'C'){
if((cmx - x) >= j) fls = 0;
if((dmx - x) < i && (cmx - x) >= j && (hmx - x) < k && (smx - x) < l) ucr = 1;
else tru = 0;
}
else if(c == 'H'){
if((hmx - x) >= k) fls = 0;
if((dmx - x) < i && (cmx - x) < j && (hmx - x) >= k && (smx - x) < l) ucr = 1;
else tru = 0;
}
else if(c == 'S'){
if((smx - x) >= l) fls = 0;
if((dmx - x) < i && (cmx - x) < j && (hmx - x) < k && (smx - x) >= l) ucr = 1;
else tru = 0;
}
}
}
}
}
if(malf == 1) sprint("ERROR");
else if(fls == 1) sprint("F");
else if(tru == 1) sprint("T");
else sprint("NG");
putchar('\n');
}
return 0;
}
E. 序列
题目描述
小Z有一个长度为
void update(int u){
int w = 0;
for(int i=1;i<=n;i++) w ^= a[i];
a[u] = w;
}
小Z可以执行这个函数若干次,其中参数
输入格式
输入第一行,包含一个正整数
第二行给定
第三行给定
输出格式
输出一行,包含一个整数,表示最小调用次数。
输入输出样例
输入:
3
0 1 2
3 1 0
输出:
2
Solution
这里首先鸣谢GCX大佬和宝<((・))>><<<《大佬协助的证明和纠错
我们先关注这个函数有什么用
发现它将整个
设初始数组为
初始所有值异或起来是
我们有
我们第一次操作将
我们的
此时所有值异或起来是
我们发现
我们尝试将
因为
所以我们将上式化简为
第二次操作将
我们实际将
我们发现了一些规律
我们的update操作,实际上就是把
其实实际上整个
我们把上面的操作看做从
因为我们最后一定会用
我们就顺利的将这道题转化为图论问题
我们的答案就是边的数量加上联通块的数量
每一条边对应一次操作
我们实际上就是想在整张图上找到最短的经过边数的路径去走遍所有的点,因为我们的操作的最小次数就是边数的最小值
我们可以更改一下题面,设有一个长度为