(换个编辑器代码就SB地不自动折叠了。。

T1 2A


考察快读的写法。

$code:$

T1
#include<bits/stdc++.h>
#define scanf SCANF=scanf
using namespace std; namespace IO{
inline int read(){
char ch=getchar(); int x=0,f=1;
while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
return x*f;
}
inline void write(int x,char sp){
char ch[20]; int len=0;
if(x<0){ putchar('-'); x=~x+1; }
do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
}
inline int max(int x,int y){ return x<y?y:x; }
inline int min(int x,int y){ return x<y?x:y; }
inline void swap(int &x,int &y){ x^=y^=x^=y; }
inline void chmax(int &x,int y){ x=x<y?y:x; }
inline void chmin(int &x,int y){ x=x<y?x:y; }
} using namespace IO; const int NN=50;
int SCANF;
int tmp,len,cnt,num[10];
bool flag;
char s[NN]; signed main(){
FILE *R=freopen("ip.in","r",stdin);
FILE *W=freopen("ip.out","w",stdout);
scanf("%s",s+1); len=strlen(s+1); tmp=1;
for(int i=1;i<=len;i++){
if(s[i]=='0'&&s[i+1]>='0'&&s[i+1]<='9') flag=1;
if(s[i]<'0'||s[i]>'9'){
++cnt;
if(s[i]!='.'||cnt>3) flag=1;
}
}
while(num[0]<5){
int x=0;
while(tmp<=len&&(s[tmp]<'0'||s[tmp]>'9')) ++tmp;
while(tmp<=len&&s[tmp]>='0'&&s[tmp]<='9'){ x=(x<<1)+(x<<3)+(s[tmp]^48); ++tmp; }
if(x>255) x=255, flag=1;
num[++num[0]]=x;
}
puts(flag?"NO":"YES");
for(int i=1;i<5;i++) write(num[i],i==4?'\n':'.');
return 0;
}

T2 2B


不会打暴力,于是切了。                                                                                                                                                                                    ——$\huge{B}$

显然的贪心:先消$AP$后消$PP$。

又发现对于每个$A$,只要它右边有足够的$P$,总能被消。因此扫一边模拟即可。不知道为啥极限数据去了$3$个零。($1e7 \to 1e4$

我写的比较麻烦,实际上从左向右扫,遇到$P$就减$A$的数量就行。

T2%%WTZ超简洁写法
#include<bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f3f3f3f3f
#define chkmax(x,y) (x)=(x>y)?(x):(y)
#define chkmin(x,y) (x)=(x<y)?(x):(y)
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
}
inline void write(int x){
static int sta[42];int top=0;
do{sta[++top]=x%10,x/=10;}while(x);
while(top) putchar(sta[top--]+'0');
return void();
}
int n,suma,sump;
char str[10010];
signed main(){
freopen("apstr.in","r",stdin);
freopen("apstr.out","w",stdout);
scanf("%s",str+1);n=strlen(str+1);
for(int i=1;i<=n;i++){
if(str[i]=='A'){suma++;}
else{
if(suma){suma--;}
else{sump++;sump%=2;}
}
}
printf("%lld\n",suma+sump);
return 0;
}
T2我的不知道为啥很麻烦的写法
#include<bits/stdc++.h>
#define scanf SCANF=scanf
using namespace std; namespace IO{
inline int read(){
char ch=getchar(); int x=0,f=1;
while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
return x*f;
}
inline void write(int x,char sp){
char ch[20]; int len=0;
if(x<0){ putchar('-'); x=~x+1; }
do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
}
inline int max(int x,int y){ return x<y?y:x; }
inline int min(int x,int y){ return x<y?x:y; }
inline void swap(int &x,int &y){ x^=y^=x^=y; }
inline void chmax(int &x,int y){ x=x<y?y:x; }
inline void chmin(int &x,int y){ x=x<y?x:y; }
} using namespace IO; const int NN=1e5+5;
int SCANF;
int n,pos,ans,sump,suma,totp,tota,rest,s[NN];
char str[NN]; signed main(){
FILE *R=freopen("apstr.in","r",stdin);
FILE *W=freopen("apstr.out","w",stdout);
scanf("%s",str+1); n=strlen(str+1); s[0]=1;
for(int i=1;i<=n;i++) s[i]=(str[i]=='P');
for(pos=n;!s[pos];pos--) ++ans;//cout<<ans<<endl;
for(int i=1;i<=pos;i++) tota+=s[i]^1, totp+=s[i];
while(pos){
sump+=s[pos]; suma+=s[pos]^1;
if(s[pos-1]&&!s[pos]){//cout<<pos-1<<' '<<suma<<' '<<sump<<endl;
rest+=max(0,suma-sump);
sump-=min(sump,suma); suma=0;
}
pos--;
}//cout<<tota<<' '<<totp<<' '<<rest<<endl;
ans+=rest;
ans+=totp-tota+rest&1;
write(ans,'\n');
return 0;
}
T2拿来对拍但依然能A的n2写法
#include<bits/stdc++.h>
#define scanf SCANF=scanf
using namespace std; namespace IO{
inline int read(){
char ch=getchar(); int x=0,f=1;
while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
return x*f;
}
inline void write(int x,char sp){
char ch[20]; int len=0;
if(x<0){ putchar('-'); x=~x+1; }
do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
}
inline int max(int x,int y){ return x<y?y:x; }
inline int min(int x,int y){ return x<y?x:y; }
inline void swap(int &x,int &y){ x^=y^=x^=y; }
inline void chmax(int &x,int y){ x=x<y?y:x; }
inline void chmin(int &x,int y){ x=x<y?x:y; }
} using namespace IO; const int NN=1e5+5;
int SCANF;
int n,pos,ans,sump,suma,totp,tota,rest,s[NN];
char str[NN]; signed main(){
freopen("in","r",stdin);
freopen("out2","w",stdout);
scanf("%s",str+1); n=strlen(str+1); s[0]=1;
for(int i=1;i<=n;i++) s[i]=(str[i]=='P');
while(n){
bool flag=0;
for(int i=1;i<=n;i++) if(s[i+1]==1&&!s[i]){
for(int j=i;j<=n-2;j++) s[j]=s[j+2];
s[n]=s[n-1]=-1;
flag=1; n-=2; break;
}
if(!flag) break;
}
// for(int i=1;i<=n;i++)cout<<s[i]<<' ';cout<<endl;
int tmp=n;
for(int i=1;i<=tmp;i+=2) if(s[i]==1&&s[i+1]==1) n-=2;
write(n,'\n');
return 0;
}

T3 2C


前两个限制很好搞,第三个限制用$bitset$记每个点的祖先,两两枚举声明的类,如果二者祖先有交且都不是对方的祖先则不合法。

也可$O(nlog)$排序后扫一遍。

$R$即祖先集合。

$code:$

T3
#include<bits/stdc++.h>
#define bst bitset<NN>
using namespace std; namespace IO{
inline int read(){
char ch=getchar(); int x=0,f=1;
while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
return x*f;
}
inline void write(int x,char sp){
char ch[20]; int len=0;
if(x<0){ putchar('-'); x=~x+1; }
do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
}
inline int max(int x,int y){ return x<y?y:x; }
inline int min(int x,int y){ return x<y?x:y; }
inline void swap(int &x,int &y){ x^=y^=x^=y; }
inline void chmax(int &x,int y){ x=x<y?y:x; }
inline void chmin(int &x,int y){ x=x<y?x:y; }
} using namespace IO; const int NN=1010;
map<string,int>has;
int n,tot,cnt;
bst anc[NN],t;
bool flag;
string nul,tmp[NN]; signed main(){
FILE *R=freopen("class.in","r",stdin);
FILE *W=freopen("class.out","w",stdout);
n=read();
while(n--){
cnt=0; flag=0;
cin>>tmp[0]>>nul;
while(tmp[cnt][0]!=';') cin>>tmp[++cnt]; --cnt; if(has.find(tmp[0])!=has.end()) flag=1;
for(int i=1;i<=cnt;i++)
if(has.find(tmp[i])==has.end()){ flag=1; break; }
if(flag){ puts("greska"); continue; } for(int i=1;i<cnt;i++)
for(int j=i+1;j<=cnt;j++){
int a=has[tmp[i]],b=has[tmp[j]];
t=anc[a]&anc[b];
if(t.none()) continue;
if(!anc[a][b]&&!anc[b][a]){ flag=1; break; }
}
puts(flag?"greska":"ok");
if(flag) continue; has[tmp[0]]=++tot;
for(int i=1;i<=cnt;i++){
anc[tot]|=anc[has[tmp[i]]];
anc[tot].set(has[tmp[i]]);
}
}
return 0;
}
/*
10
shape : ;
rectangle : shape ;
circle : shape ;
circle : ;
square : shape rectangle ;
runnable : object ;
object : ;
runnable : object shape ;
thread : runnable ;
applet : square thread ;
*/

T4 2D


枚举$k$,每次在子图中$DFS$记录答案,然后拓扑排序将度数为$k$的点删掉,继续枚举$k+1$。

看起来及其暴力,但由于$n,m$同级所以不大好卡,即使被卡了也可以优化枚举策略。

注意开始时要把度数为$0$的点先删掉。

$code:$

T4
#include<bits/stdc++.h>
using namespace std;
typedef long long LL; namespace IO{
inline int read(){
char ch=getchar(); int x=0,f=1;
while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
return x*f;
}
inline void write(LL x,char sp){
char ch[20]; int len=0;
if(x<0){ putchar('-'); x=~x+1; }
do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
}
inline int max(int x,int y){ return x<y?y:x; }
inline int min(int x,int y){ return x<y?x:y; }
inline void swap(int &x,int &y){ x^=y^=x^=y; }
inline void chmax(int &x,int y){ x=x<y?y:x; }
inline void chmin(int &x,int y){ x=x<y?x:y; }
} using namespace IO; const int NN=1e6+5;
int n,m,mx,idx,to[NN<<1],head[NN],nex[NN<<1],in[NN],deg[NN],res;
LL M,N,B,mm,nn,bb,now,ans; int l,r,sum,q[NN];
bool ban[NN],vis[NN];
inline void add(int a,int b,int i){
to[++idx]=b; nex[idx]=head[a]; head[a]=idx; ++deg[a]; chmax(mx,deg[a]);
to[++idx]=a; nex[idx]=head[b]; head[b]=idx; ++deg[b]; chmax(mx,deg[b]);
} void dfs(int s){
bb+=in[s]; ++nn; vis[s]=1;
for(int i=head[s];i;i=nex[i]){
int v=to[i];
if(ban[v]) continue;
++mm;
if(!vis[v]) dfs(v);
}
} void topo(int lmt){
l=1; r=0;
for(int i=1;i<=n;i++)
if(!ban[i]&&deg[i]==lmt) ban[i]=1, q[++r]=i, --sum;
while(l<=r){
int x=q[l++];
for(int i=head[x];i;i=nex[i]) if(!ban[to[i]]){
--deg[to[i]];
if(deg[to[i]]==lmt)
ban[to[i]]=1, q[++r]=to[i], --sum;
}
}
} signed main(){
FILE *R=freopen("kdgraph.in","r",stdin);
FILE *W=freopen("kdgraph.out","w",stdout);
n=sum=read(); m=read(); M=read(); N=read(); B=read(); ans=-1e18;
for(int a,b,i=1;i<=m;i++)
a=read(),b=read(), add(a,b,i);
for(int i=1;i<=n;i++){
in[i]=deg[i];
if(!in[i]) --sum, ban[i]=1;
}
for(int k=1;k<=mx&&sum;k++){
for(int i=1;i<=n;i++) vis[i]=0;
for(int i=1;i<=n;i++) if(!ban[i]&&!vis[i]){
mm=0; bb=0; nn=0;
dfs(i);
bb-=mm; mm>>=1;
now=mm*M-nn*N+bb*B;
if(now>=ans) res=k, ans=now;
}
topo(k);
}
write(res,' '); write(ans,'\n');
return 0;
}
 
 
 
 
 
 

2021.9.20考试总结[NOIP模拟57]的更多相关文章

  1. 2021.9.17考试总结[NOIP模拟55]

    有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...

  2. 2021.9.13考试总结[NOIP模拟52]

    T1 路径 考虑每一位的贡献,第$i$位每$2^i$个数会变一次,那么答案为$\sum_{i=1}^{log_2n} \frac{n}{2^i}$. $code:$ 1 #include<bit ...

  3. 2021.8.11考试总结[NOIP模拟36]

    T1 Dove玩扑克 考场并查集加树状数组加桶期望$65pts$实际$80pts$,考后多开个数组记哪些数出现过,只扫出现过的数就切了.用$set$维护可以把被删没的数去掉,更快. $code:$ 1 ...

  4. 2021.7.29考试总结[NOIP模拟27]

    T1 牛半仙的妹子图 做法挺多的,可以最小生成树或者最短路,复杂度O(cq),c是颜色数. 我考场上想到了原来做过的一道题影子,就用了并查集,把边权排序后一个个插入,记录权值的前缀和,复杂度mlogm ...

  5. 2021.7.15考试总结[NOIP模拟16]

    ZJ模拟D2就是NB.. T1 Star Way To Heaven 谁能想到这竟是个最小生成树呢?(T1挂分100的高人JYF就在我身边 把上边界和下边界看成一个点和星星跑最小生成树,从上边界开始跑 ...

  6. 2021.9.14考试总结[NOIP模拟53]

    T1 ZYB和售货机 容易发现把每个物品都买成$1$是没有影响的. 然后考虑最后一个物品的方案,如果从$f_i$向$i$连边,发现每个点有一个出度多个入度,可以先默认每个物品都能买且最大获利,这样可以 ...

  7. 2021.9.12考试总结[NOIP模拟51]

    T1 茅山道术 仔细观察发现对于每个点只考虑它前面第一个与它颜色相同的点即可. 又仔细观察发现对一段区间染色后以这个区间内点为端点的区间不能染色. 于是对区间右端点而言,区间染色的贡献为遍历到区间左端 ...

  8. 2021.9.9考试总结[NOIP模拟50]

    T1 第零题 神秘结论:从一个点满体力到另一个点的复活次数与倒过来相同. 于是预处理出每个点向上走第$2^i$个死亡点的位置,具体实现可以倍增或二分. 每次询问先从两个点同时向上倍增,都转到离$LCA ...

  9. 2021.9.7考试总结[NOIP模拟49]

    T1 Reverse $BFS$暴力$O(n^2)$ 过程中重复枚举了很多点,考虑用链表记录当前点后面可到达的第一个未更新点. 搜索时枚举翻转子串的左端点,之后便可以算出翻转后$1$的位置. $cod ...

随机推荐

  1. v-for列表渲染之数组变动检测

    1.简单举一个v-for列表渲染例子 <template> <div> <ul> <li v-for="item in items"> ...

  2. jmeter 参数化学习之CSV Data Set Config随机读取一行参数

    需要使用到循环控制器,if控制器,CSV Data Set Config,Random Variable 4个组件 如图 先在线程组下面放一个随机数生成器 然后在同一层级设置一个永久的循环控制器,记住 ...

  3. Django学习day08随堂笔记

    今日考题 """ 今日考题 1.聚合查询,分组查询的关键字各是什么,各有什么特点或者注意事项 2.F与Q查询的功能,他们的导入语句是什么,针对Q有没有其他用法 3.列举常 ...

  4. 【tp6】解决Driver [Think] not supported.

    使用助手函数view时会出现 解决方法:使用composer安装composer require topthink/think-view

  5. Linux系列(6) - 常见目录

    linux 一级目录有严格规定,脚本文件等放在root/home/tmp目录中,减少在根目录的操作 目录名称 作用 / 根目录 /bin 命令保存目录(普通用户就可以读取的命令); 根目录下的bin和 ...

  6. FreeRTOS-06-信号量

    说明 本文仅作为学习FreeRTOS的记录文档,作为初学者肯定很多理解不对甚至错误的地方,望网友指正. FreeRTOS是一个RTOS(实时操作系统)系统,支持抢占式.合作式和时间片调度.适用于微处理 ...

  7. 关于spring boot+maven项目大面积报红

    有时候我们使用git拉取代码,首先代码本身是没有任何问题的,但我们拉取的代码却大面积报红,模块间的类显示无法加载上方导进来的包一片灰, 代码部分大面积报红,在代码可以确定没问题的情况下,可这样操作: ...

  8. 卧槽,redis分布式如果用不好,坑真多

    前言 在分布式系统中,由于redis分布式锁相对于更简单和高效,成为了分布式锁的首先,被我们用到了很多实际业务场景当中. 但不是说用了redis分布式锁,就可以高枕无忧了,如果没有用好或者用对,也会引 ...

  9. Python读取ini配置文件(接口自动测试必备)

    前言 大家应该接触过.ini格式的配置文件.配置文件就是把一些配置相关信息提取出去来进行单独管理,如果以后有变动只需改配置文件,无需修改代码. 特别是后续做自动化的测试,代码和数据分享,进行管理.比如 ...

  10. asp.net core 中配合响应 html5 的音视频播放流,以及文件下载

    一.asp.net core 中配合响应 html5 的音视频播放流,以及文件下载 问题描述: 目前测试了在 Windows(谷歌浏览器).Android(系统浏览器.QQ.微信).iOS 三个系统不 ...