A - Avoiding Zero

不难发现如果数组所有元素和为0一定不能满足条件,否则一定能满足。
假设所有元素和不为0尝试以下构造,如果正数和小于负数和的绝对值,那么逆序排列,否则顺序排列,这样一定满足题意。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=60;
int a[N];
int main()
{IO;int T=1;cin>>T;while(T--){int n;cin>>n;int s=0;int s1=0,s2=0;for(int i=1;i<=n;i++){cin>>a[i];if(a[i]<0) s1+=a[i];else s2+=a[i];s+=a[i];}if(s==0){cout<<"NO\n";continue;}sort(a+1,a+1+n);if(-s1<s2) reverse(a+1,a+1+n);  cout<<"YES\n";for(int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<'\n';}return 0;}

B - Chess Cheater

瞎搞的

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=100010;
char s[N];
int n,k;
int main()
{IO;int T=1;cin>>T;while(T--){cin>>n>>k;cin>>s+1;priority_queue<int,vector<int>,greater<int>> q1,q2,q3;priority_queue<int> p1,p2;int cnt=0;for(int i=1;i<=n;i++){if(s[i]=='L') cnt++;else {if(!cnt) continue;if(i>cnt+1&&s[i-cnt-1]=='W'&&i<=n&&s[i]=='W') q1.push(cnt);else if(i>cnt+1&&s[i-cnt-1]=='W'||i<=n&&s[i]=='W') q2.push(cnt);else q3.push(cnt);cnt=0;}}if(cnt) {if(n>cnt&&s[n-cnt]=='W') q2.push(cnt);else q3.push(cnt);}int res=0;while(k&&q1.size()){auto v=q1.top();q1.pop();if(k>=v) res+=2*v+1,k-=v;else p1.push(v);}while(k&&q2.size()){auto v=q2.top();q2.pop();if(k>=v) res+=2*v,k-=v;else p2.push(v);}while(k&&(p1.size()||p2.size())){res+=2*k;k=0;}if(k&&q3.size()) {auto v=q3.top();res=2*min(k,v)-1;}for(int i=1;i<=n;i++){if(s[i]=='W'){if(i>1&&s[i-1]=='W') res+=2;else res++;}}cout<<res<<'\n';}return 0;
}

C - The Hard Work of Paparazzi

刚开始以为是个图论题,但是有一个条件就是就算你先到了一个点你仍然要等到那个人出现的时间,也就是每个点的时间是确定的,因此每个点的时间是确定的考虑dp
状态表示:fif_ifi​表示目前在第iii个点时答案的最大值
状态转移:fi=max(fi,fi+1)(∣xi−xj∣+∣yi−yj∣≤ti−tj)f_i=max(f_i,f_i+1)(|x_i-x_j|+|y_i-y_j|\leq t_i-t_j)fi​=max(fi​,fi​+1)(∣xi​−xj​∣+∣yi​−yj​∣≤ti​−tj​)

这样转移会发现复杂度爆炸O(n2)O(n^2)O(n2),我们可以发现还有个东西一直没有用也就是地图的尺寸rrr,由于tit_iti​是顺序给出的如果当前的ti−tj≥2rt_i-t_j\ge 2rti​−tj​≥2r不难发现1−j1-j1−j的f1−jf_{1-j}f1−j​都能更新fif_ifi​由此尝试维护前缀进行优化。
时间复杂度好像是O(nr)O(nr)O(nr)

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=100010;
int r,n;
int f[N];
struct node
{int x,y,t;
}a[N];
int mx[N];
int main()
{IO;int T=1;//cin>>T;while(T--){cin>>r>>n;for(int i=1;i<=n;i++) cin>>a[i].t>>a[i].x>>a[i].y;memset(f,-0x3f,sizeof f);memset(mx,-0x3f,sizeof mx);a[0]={1,1,0};f[0]=mx[0]=0;for(int i=1;i<=n;i++){for(int j=i-1;j>=0;j--){if(a[i].t-a[j].t>=2*r) {f[i]=max(f[i],mx[j]+1);break;}if(abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y)<=a[i].t-a[j].t) f[i]=max(f[i],f[j]+1);}mx[i]=max(mx[i-1],f[i]);}int res=0;for(int i=1;i<=n;i++) res=max(res,f[i]);cout<<res<<'\n';}return 0;
}

剩下的题待补

D - Unshuffling a Deck

今天早上起来想了一下这个题,想了个贪心的做法然后上课前交代码发现贪心思路不行,然后吃完午饭又想了个做法水过去了

尝试每次使得一个数排列归位。这里尝试按照n−1n−2…1n-1\ n-2\dots \ 1%n−1 n−2… 1的顺序
首先我们让排好序的排成(目前已经有cnt个数“归位”)这样子{[n,n−1,n−2,...,n−cnt+1][...n−cnt][....]}\{[n,n-1,n-2,...,n-cnt+1][...n-cnt][....]\}{[n,n−1,n−2,...,n−cnt+1][...n−cnt][....]}我们只需要这样划分就可以在此归位一个数
{[1]...[1][1]⏟cnt[len1][len2]}\{ \underbrace{[1]...[1][1]}_{cnt}[len_1][len_2]\}{cnt[1]...[1][1]​​[len1​][len2​]}
这样操作后原序列即变成{[......][n−cnt,n−cnt+1,...,n]}\{[......][n-cnt,n-cnt+1,...,n]\}{[......][n−cnt,n−cnt+1,...,n]}
然后如法炮制的操作,一共进行n次即可归位。还有些细节可以看代码

细节1:n奇偶性,最后一次操不能让序列变成全部逆序的情况,需要顺序
细节2:划分需要至少划分2个断,最后需要把划分成1个段(无效操作)清除掉。

上述方法一定能在n次操作以内完成序列顺序。


#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=60;
int n,cnt;
int a[N],b[N];
vector<int> ans[N];
int main()
{IO;int T=1;//cin>>T;while(T--){cin>>n;for(int i=1;i<=n;i++) cin>>a[i];bool flag;int now=n;if(n&1) flag=0;else flag=1;for(int k=1;k<=n;k++){int p;for(int i=1;i<=n;i++) if(a[i]==now) p=i;//cout<<p<<':';//cout<<(int)flag<<'\n';if(!flag)// 左边整齐{for(int i=1;i<=cnt;i++) ans[k].push_back(1);if(p-cnt) ans[k].push_back(p-cnt);if(n-p) ans[k].push_back(n-p);for(int i=p+1,j=1;i<=n;i++,j++) b[j]=a[i];// p+1~n -> 1~n-p    n-pfor(int i=cnt+1,j=n-p+1;i<=p;i++,j++) b[j]=a[i];// cnt+1~p -> n-p+1   p-cntfor(int i=1,j=n;i<=cnt;i++,j--) b[j]=a[i];// 1~cnt -> n~n-cnt+1  cntfor(int i=1;i<=n;i++) a[i]=b[i];}else{if(p-1>0) ans[k].push_back(p-1);if(n-cnt-p+1>0) ans[k].push_back(n-cnt-p+1);for(int i=1;i<=cnt;i++) ans[k].push_back(1);for(int i=1,j=n-p+2;i<=p-1;i++,j++) b[j]=a[i];for(int i=p,j=cnt+1;i<=n-cnt;i++,j++) b[j]=a[i];for(int i=n-cnt+1,j=cnt;i<=n;i++,j--) b[j]=a[i];for(int i=1;i<=n;i++) a[i]=b[i];}now--;cnt++;flag^=1;}int res=0;for(int i=1;i<=n;i++)if(ans[i].size()>1) res++;cout<<res<<'\n';for(int i=1;i<=n;i++){if(ans[i].size()>1){cout<<ans[i].size()<<' ';for(auto t:ans[i]) cout<<t<<' ';cout<<'\n';}}}return 0;
}

E - Xum

要加哟哦~

Codeforces Global Round 11——E随机+线性基待补相关推荐

  1. Codeforces Global Round 11 ABCD题解

    真阴间啊 , 不仅时长阴间, 题目也有点emmmmm 打的不顺利,没有按预想在15分钟内把AB题写出来 ((。・∀・)ノ゙害) 开局码了发A WA2 人傻了 开始质疑自己了 先搁着吧 然后又码了一个半 ...

  2. Codeforces Global Round 11 C. The Hard Work of Paparazzi

    题目链接 思路:读完题看到r的范围就能发现一个小trick.时间相距超过2r的两个明星必然有一种方式可以同时拍到.由于时间严格递增,那么暴力转移dp最多只有2r个初态,直接暴力即可.时间超过2r的可以 ...

  3. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

  4. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集

    传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai​,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau​+av​≥x ...

  7. Codeforces Global Round 1

    Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...

  8. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  9. codeforces global round 23

    constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...

最新文章

  1. java全能速查宝典.chm_Java API 快速速查宝典
  2. 自定义注解加AOP怎么玩?
  3. Linux uptime指令
  4. 如何设计日志系统_架构 - 如何设计一个百亿级日志系统
  5. 教你玩转CSS 组合选择符
  6. 简单的for()循环使用方式foreach
  7. .NET下的验证码控件John.Controls.ValidateCode2V for .NET beta1
  8. 2018年人工智能行业研究报告
  9. 图片少量显示 9张一下 类似微信,微博客户端
  10. px和毫米的换算_px和厘米怎么换算?
  11. 基于multisim的zcs电路仿真
  12. 4.5.2 Stress Testing
  13. computed 和 watch的区别
  14. 计算机关闭自带杀毒,电脑系统自带杀毒软件怎么关闭?两种Windows defender彻底关闭方法(图文)...
  15. java在字符串开头添加字符串_string - java:使用StringBuilder在开头插入
  16. 自然数 素数 质数_俄罗斯娃娃素数
  17. C语言中访问结构体成员时 点 . 和 箭头 - 的区别
  18. 离线状态下IDEA导入Maven依赖爆红解决
  19. 浅谈香港服务器的优势
  20. mui关闭页面plus.webview.currentWebview().close();使用后页面闪现一下的问题解决

热门文章

  1. java递归单链表查找中间元素_《数据结构与算法——C语言描述》答案 3.11 查找单链表中的特定元素(递归)...
  2. php多进程 写入文件_PHP多进程中使用file_put_contents安全吗?
  3. typora公式zuo对齐_Markdown编辑神器-Typora
  4. 嵌入式linux pcie网卡配置,嵌入式Linux下PCIE数据采集卡驱动开发
  5. 你真的理解事件绑定、事件冒泡和事件委托吗?
  6. android 片段,android – 将片段添加到片段中(嵌套片段)
  7. 数据结构与算法--经典10大排序算法(动图演示)【建议收藏】
  8. oracle错误 904,ORACLE 导出错误 EXP-00008: 遇到 Oracle 错误 904
  9. 量子力学问题matlab求解,一个关于量子力学中的matlab的问题
  10. Lingo优化模型概述