Test41普转提考试总结
Claire0630 · · 题解
Test41普转提考试总结
Data
Score:40 = 10 + 10 + 20 + 0
Rank: B组P14,全组P30(diandi)
Preface
坐牢了孩子们,成功再次坠机>___< /(ㄒoㄒ)/~~
浙江的题还是太权威太有水平了:(
确实是想不到,跟状态可能有点关系,但大体还是思路问题,根本就没在正解的路上
T1想到二分就起飞了
T2啥都没想也起飞了
T3没有用数字优化还起飞了
T4瞎JB乱写本来就起飞了
啊啊啊o((>ω< ))o要死了
qc真的要死了
救救QC吧
Statements
A. 玩具(toy)
题面
有
输入格式
第一行:
第二行:
接下来
最后一行:初始分
输出格式
最大得分
数据范围
-
对于 20% 的数据:
t \leq 10, n \leq 10, k_i \leq 10 -
对于另外 10% 的数据:数组
a 中的数全部相同 -
对于另外 10% 的数据:数组
k 中的数全部相同 -
对于 60% 的数据:
t \leq 10000, n \leq 10000 -
对于 100% 的数据:
t \leq 100000, n \leq 100000, k_i \leq 100, w_i \leq 100, s \leq 100, 1 \leq l_i \leq r_i \leq n, 1 \leq a_i \leq 10000
样例输入
Input
2 5
2 1 5 2 4 3
2 5 7 4
1 3 9 10
100
Output
94
Solution
此题因为要满足连续区间是
我们使用前缀和
这里给一组小数据(甚至逆天到考试的二分代码都能通过???) Input:
7 10
1 3 4 2 5 8 6 7 9 11
3 5 1 10
4 9 7 10
1 1 100 10
1 10 11 10
5 6 13 10
6 10 17 10
6 10 18 10
100
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;//super_long_long
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int>> PIP;
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,M = 1e2 + 11;
LL t,n,org;
LL a[N],s[N],ys[N];
vector<int> v[M];
struct node{
int l,r,k,w;
}g[N];
int main(){
// freopen("ex_0.in","r",stdin);
// freopen("toy.out","w",stdout);
read(t);read(n);
for(LL i=1;i<=n;i++) read(a[i]);
for(LL i=1;i<=n;i++) s[i] = s[i - 1] + a[i];
for(LL i=1;i<=t;i++){
read(g[i].l);read(g[i].r);read(g[i].k);read(g[i].w);
v[g[i].k].emplace_back(i);
}
read(org);
for(int i=0;i<=100;i++){
if(v[i].size() == 0) continue;
for(int j=1;j<=n;j++) ys[j] = s[j] % i;
for(auto x : v[i]){
int l = g[x].l,r = g[x].r;
map<int,int> mp;
mp.clear();
bool fl = 0;
for(int k=l-1;k<=r;k++){
if(mp.find(ys[k]) != mp.end()){
fl = 1;
break;
}
mp[ys[k]] = k;
}
if(fl == 1) org += g[x].w;
else org -= g[x].w;
}
}
print(org);
return 0;
}
B. 数列(seq)
题面
给定数列
-
b_i > 0 -
a_i - k \leq b_i \leq a_i - 去掉
f 个元素后,剩余b_i 的最大公约数为g
输出所有可能的
输入格式
第一行:
每组数据:
- 第一行:
n, k, f - 第二行:
n 个整数a_i
输出格式
每组数据一行,升序输出所有满足条件的
样例输入
1
6 3 1
78 69 55 102 233 666
样例输出
1 2 3 4 5 6 11
数据范围
设
| 测试点编号 | ||
|---|---|---|
| 1-6 | - | |
| 7-10 | - | |
| 11-12 | ||
| 13-14 | - | |
| 15-16 | - | |
| 17-18 | - | |
| 19-20 |
Solution
我们观察到要满足有至少
我们先使用前缀和将所有的元素个数累加起来
我们可以将所有可能的
对于
我们将区间
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;//super_long_long
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int>> PIP;
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 = 2e6 + 11,M = 25;
int t,n,k,f;
int a[N],mp[N],s[N],c[N];
//unordered_map<int,int> mp;
void init(){
for(int i=1;i<=N-11;i++) mp[i] = s[i] = c[i] = 0;
return;
}
int main(){
// freopen("seq.in","r",stdin);
// freopen("seq.out","w",stdout);
read(t);
while(t --){
read(n);read(k);read(f);
init();
for(int i=1;i<=n;i++){
read(a[i]);
mp[a[i]] ++;
}
for(int i=1;i<=N-11;i++) s[i] = s[i - 1] + mp[i];
for(int i=1;i<=k+1;i++){
if(s[N - 11] - s[i - 1] >= n - f){
print(i);
putchar(' ');
}
}
for(int i=1;i<=n;i++){
int l = max(1,a[i] - k),r = a[i];
c[l] ++,c[r + 1] --;
}
for(int i=1;i<=N-11;i++) c[i] += c[i - 1];
for(int i=k+2;i<=N-11;i++){
int cnt = 0;
for(int j=i;j<=N-11;j+=i) cnt += c[j];
if(cnt >= n - f){
print(i);
putchar(' ');
}
}
putchar('\n');
}
return 0;
}
C. 文件(file)
题面
有一个
输入格式
第一行:
接下来
接下来
输出格式
解密后的
样例输入
4 4 2
a a b b
a a b b
c c d d
c c d d
1 1 3 3 2 2
3 1 1 3 2 2
样例输出
d d c c
d d c c
b b a a
b b a a
数据范围
- 对于前 30% 的数据:
|S| \leq n \times m - 对于前 60% 的数据:
n, m \leq 100 - 对于 100% 的数据:
n, m \leq 1000, q \leq 5000, |S| \leq 10^7
Solutions
S1.半暴力大法
因为此题时限赌狗WLS的豪赌下,竟然AC了??!!!,其实我TM随便加强点数据(
王屎山代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;//super_long_long
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int>> PIP;
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 read(string &s){
s = "";
char c = getchar();
while(c == ' ' || c == '\n' || c == '\r') c = getchar();
while(c != ' ' && c != '\n' && c != '\r' && c != EOF){
s += c;
c = getchar();
}
}
inline void print(const string &s){
for(char c : s) putchar(c);
}
const int N = 1e3 + 11,M = 25;
int n,m,q,cnt;
string g[N * N];
int a[N][N];
map<PII,PII> pos;
int main(){
// freopen("ex_0.in","r",stdin);
// freopen("file.out","w",stdout);
read(n);read(m);read(q);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
read(g[++ cnt]);
a[i][j] = cnt;
}
}
while(q --){
int x1,y1,x2,y2,l,c;
read(x1);read(y1);read(x2);read(y2);read(l);read(c);
for(int i=x1,i2=x2;i<x1+l;i++,i2++){
for(int j=y1,j2=y2;j<y1+c;j++,j2++){
swap(a[i][j],a[i2][j2]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
print(g[a[i][j]]);
putchar(' ');
}
putchar('\n');
}
return 0;
}
S2.正解
还是Cdo大佬权威,这个做法还是太NB太快了
我们分析矩形交换的实际含义
我们发现两个矩形的交换就是断开与原来上下左右四个方向的边框并重新连上新位置的四个边框,因为我们并不能实际的交换位置,所以只能寻找和四周的关系,于是我们就可以使用链表(最好是手写的)来实现这个题目,对于每个点,我们并不需要上下左右四个方向的连接,只需要与右方和下方衔接即可
我们枚举矩形的四个边,将边上的点交换所指向的位置即可,注意边界的处理!
实现:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;//super_long_long
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int>> PIP;
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 read(string &s){
s = "";
char c = getchar();
while(c == ' ' || c == '\n' || c == '\r') c = getchar();
while(c != ' ' && c != '\n' && c != '\r' && c != EOF){
s += c;
c = getchar();
}
}
inline void print(const string &s){
for(char c : s) putchar(c);
}
const int N = 1e3 + 11,M = 2e6 + 11;
int n,m,q,cnt;
string g[N][N];
struct node{
int x,y,r,d;
}a[M];
int find_pos(int x,int y){
int pos = 1;
for(int i=1;i<x;i++) pos = a[pos].d;
for(int i=1;i<y;i++) pos = a[pos].r;
return pos;
}
int main(){
// freopen("ex_0.in","r",stdin);
// freopen("file.out","w",stdout);
read(n);read(m);read(q);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) read(g[i][j]);
}
for(int i=0;i<=n+1;i++){
for(int j=0;j<=m+1;j++){
a[++ cnt].x = i;
a[cnt].y = j;
a[cnt].d = cnt + m + 2;
a[cnt].r = cnt + 1;
}
}
while(q --){
int xl,yl,xr,yr,l,c;
read(xl);read(yl);read(xr);read(yr);read(l);read(c);
int rg1 = find_pos(xl,yl),rg2 = find_pos(xr,yr),tp1 = rg1,tp2 = rg2;
for(int i=1;i<=l;i++){
tp1 = a[tp1].d;
tp2 = a[tp2].d;
int x = a[tp1].r,y = a[tp2].r;
a[tp1].r = y;
a[tp2].r = x;
}
for(int i=1;i<=c;i++){
tp1 = a[tp1].r;
tp2 = a[tp2].r;
int x = a[tp1].d,y = a[tp2].d;
a[tp1].d = y;
a[tp2].d = x;
}
tp1 = rg1,tp2 = rg2;
for(int i=1;i<=c;i++){
tp1 = a[tp1].r;
tp2 = a[tp2].r;
int x = a[tp1].d,y = a[tp2].d;
a[tp1].d = y;
a[tp2].d = x;
}
for(int i=1;i<=l;i++){
tp1 = a[tp1].d;
tp2 = a[tp2].d;
int x = a[tp1].r,y = a[tp2].r;
a[tp1].r = y;
a[tp2].r = x;
}
}
int st = a[a[1].d].r;
for(int i=1;i<=n;i++){
int p = st;
for(int j=1;j<=m;j++){
print(g[a[p].x][a[p].y]);
p = a[p].r;
putchar(' ');
}
st = a[st].d;
putchar('\n');
}
return 0;
}
D. 排列(permutation)
题面
有一个长度为
输入格式
第一行:
接下来
输出格式
一行
数据范围
样例输入
5 4
1 2 3
2 3 4
3 4 5
4 5 1
样例输出
1 4 3 2 5
Solution
我们思考这道题时,发现此题有SPJ,但问题不大
首先可以枚举所有可能的排列情况,再逐一检查是否满足条件,满足就输出,时间复杂度
我们就不多bb了,这题部分分还很多,我们直奔主题
反正我做这道题时考场上是想到了和差分约束的相关东西,因为如果这道题明显规定了
但,没这么简单,对于此题,
对于我们刚刚想到的词-----拓扑排序
OK!恭喜你找到此题正解
我们来看如何进行建图
这样进行建图,我们保证在
这样保证
我们进行答案统计时要将三元组的最后一个元素归位时才记录答案,不然会重复,出现矛盾
在统计答案时,我们要把答案从两边往中间记录,这样可以保证先确定两边位置,再确定中间位置,在拓扑到每个点时,去枚举每个包含这个点的三元组,去计算放在当前的最左边还是最右边符合的方案数更多,选择方案数较多的一边记录即可,这样也符合拓扑序,我们就可以边拓扑便记录答案,就更方便.因为每次符合的三元组数量都比不符合的多,就一定可以满足大于等于
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;//super_long_long
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int>> PIP;
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,M = 25;
int n,m,l,r;
struct node{
int x,y,z;
}a[N];
int iD[N],ans[N],pos[N];
bool st[N];
vector<node> ed[N],md[N];
void add(int u){
int cntl = 0,cntr = 0;
for(auto x : ed[u]){
if(pos[x.x] == 0 && pos[x.y] > 0){
if(pos[x.y] < l) cntr ++;
else cntl ++;
}
}
for(auto x : md[u]){
if(pos[x.x] == 0 && pos[x.y] > 0){
if(pos[x.y] < l) cntl ++;
else cntr ++;
}
if(pos[x.y] == 0 && pos[x.x] > 0){
if(pos[x.x] < l) cntl ++;
else cntr ++;
}
}
if(cntl >= cntr){
pos[u] = l;
ans[l] = u;
l ++;
}else{
pos[u] = r;
ans[r] = u;
r --;
}
return;
}
void toposort(){
queue<int> q;
for(int i=1;i<=n;i++){
if(iD[i] == 0) q.push(i);
}
while(q.size()){
int t = q.front();
q.pop();
add(t);
for(auto x : ed[t]){
if(st[x.z] == 1) continue;
st[x.z] = 1;
iD[x.x] -= 2;
if(iD[x.x] == 0) q.push(x.x);
}
}
}
int main(){
// freopen("permutation.in","r",stdin);
// freopen("permutation.out","w",stdout);
read(n);read(m);
l = 1,r = n;
for(int i=1;i<=m;i++){
read(a[i].x);read(a[i].y);read(a[i].z);
iD[a[i].y] += 2;
ed[a[i].x].emplace_back((node){a[i].y,a[i].z,i});
ed[a[i].z].emplace_back((node){a[i].y,a[i].x,i});
md[a[i].y].emplace_back((node){a[i].x,a[i].z,i});
}
toposort();
for(int i=1;i<=n;i++){
print(ans[i]);
putchar(' ');
}
return 0;
}