清北刷题冲刺 11-02 a.m
卖书

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1000010
using namespace std;
int n,a[maxn],cnt1,cnt2;
int qread(){
int i=;
char ch=getchar();
while(ch<''||ch>'')ch=getchar();
while(ch<=''&&ch>=''){i=i*+ch-'';ch=getchar();}
return i;
}
int main(){
freopen("book.in","r",stdin);freopen("book.out","w",stdout);
// freopen("Cola.txt","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;i++)a[i]=qread();
for(int i=;i<=n;i++){
if(a[i]==)cnt1++;
if(a[i]==){
if(cnt1==){
puts("NO");
return ;
}
else {
cnt2++;
cnt1--;
}
}
if(a[i]==){
if(cnt1==||(cnt2==&&cnt1<)){
puts("NO");
return ;
}
if(cnt2){
cnt2--;
cnt1--;
}
else{
cnt1-=;
}
}
}
puts("YES");return ;
}
100分 贪心
写代码

#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000010
using namespace std;
int n,a[maxn],s1[maxn],s2[maxn],top1,top2,m,sid1[maxn],sid2[maxn],b[maxn];
bool ex[maxn];
void out(){
for(int i=;i<=n;i++){
if(b[i]==)printf("+%d ",a[i]);
else printf("-%d ",a[i]);
}
}
int main(){
freopen("program.in","r",stdin);freopen("program.out","w",stdout);
// freopen("Cola.txt","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
scanf("%d",&m);int x;
for(int i=;i<=m;i++){scanf("%d",&x);ex[x]=;}
for(int i=;i<=n;i++){
if(ex[i]){
top2+=;
s2[top2]=a[i];b[i]=-;
sid2[top2]=i;
while(top2){
if(s2[top2]==s1[top1]){
b[sid2[top2]]=-;
b[sid1[top1]]=;
top1-=;top2-=;
}
else{
sid2[top2+]=sid1[top1];
top2+=;
s2[top2]=s1[top1];top1-=;
}
if(top1<){puts("NO");return ;}
}
}
else{
top1+=;
s1[top1]=a[i];
sid1[top1]=i;
}
}
if(top1==&&top2==){
out();
return ;
}
while(top1){
s2[++top2]=s1[top1];
sid2[top2]=sid1[top1];top1--;
while(top2){
if(s2[top2]==s1[top1]){
b[sid2[top2]]=-;
b[sid1[top1]]=;
top1--;top2--;
}
else{
sid2[top2+]=sid1[top1];
s2[++top2]=s1[top1--];
}
if(top1<){puts("NO");return ;}
}
}
out();return ;
}
100分 括号匹配
迷宫



#include<iostream>
#include<cstdio>
#include<vector>
#define maxn 110
using namespace std;
int n,m,num,head[maxn],q,s,t,st[maxn],top;
struct node{
int to,pre,v;
}e[maxn*maxn*];
void Insert(int from,int to,int v){
e[++num].to=to;
e[num].v=v;
e[num].pre=head[from];
head[from]=num;
}
bool vis[maxn],flag;
void dfs(int now){
if(now==t&&top==){
flag=;
return;
}
if(flag)return;
vector<int>zu;
for(int i=;i<=top;i++)zu.push_back(st[i]);
for(int i=head[now];i;i=e[i].pre){
int to=e[i].to;
if(vis[to])continue;
else{
vis[to]=;
if(e[i].v==){
dfs(to);
top=;
for(int j=;j<zu.size();j++)st[++top]=zu[j];
vis[to]=;
continue;
}
for(int j=;j<=;j+=){
if(e[i].v>){
for(int k=;k<=j;k++){
top=top+;
st[top]=e[i].v;
}
dfs(to);
if(flag)return;
top=;
for(int k=;k<zu.size();k++)top=top+,st[top]=zu[k];
}
if(e[i].v<){
top-=j-;
if(st[top]!=-e[i].v||top<)break;
else top-=;
dfs(to);
top=;
for(int k=;k<zu.size();k++)st[++top]=zu[k];
}
}
vis[to]=;
}
}
}
int main(){
freopen("maze.in","r",stdin);freopen("maze.out","w",stdout);
// freopen("Cola.txt","r",stdin);
scanf("%d%d",&n,&m);
int x,y,z;
for(int i=;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
Insert(x,y,z);Insert(y,x,z);
}
scanf("%d",&q);
while(q--){
flag=;top=;
scanf("%d%d",&s,&t);
vis[s]=;
dfs(s);
vis[s]=;
if(flag)puts("YES");
else puts("NO");
}
return ;
}
5分 暴力
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
int n,m,g[][][],q[**][],t,x,y,z;
int main(){
// freopen("maze.in","r",stdin);freopen("maze.out","w",stdout);
freopen("maze20.in","r",stdin);
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
if(z!=){
if(z<)z=abs(z);
else z+=;
g[x][y][z]=;g[y][x][z]=;
}
else{
g[x][y][z]=;g[y][x][z]=;
t++;q[t][]=x;q[t][]=y;q[t][]=;
t++;q[t][]=y;q[t][]=x;q[t][]=;
}
}
for(int i=;i<=n;i++){
g[i][i][]=;
t++;q[t][]=i;q[t][]=i;q[t][]=;
}
for(int s=;s<=t;s++){
int x=q[s][],y=q[s][],sta=q[s][];
if(sta!=){
for(int i=;i<=n;i++){
if(g[i][x][sta-]==){
if(g[i][y][]==){
g[i][y][]=;
t++;q[t][]=i;q[t][]=y;q[t][]=;
}
}
}
}
else{
for(int i=;i<=n;i++){
if(g[i][x][]==&&g[i][y][]==){
g[i][y][]=;
t++;q[t][]=i;q[t][]=y;q[t][]=;
}
if(g[y][i][]==&&g[x][i][]==){
g[x][i][]=;
t++;q[t][]=x;q[t][]=i;q[t][]=;
}
for(int j=;j<=;j++){
if(g[y][i][j]==&&g[x][i][j+]==){
g[x][i][j+]=;
t++;q[t][]=x;q[t][]=i;q[t][]=j+;
}
}
}
}
}
int tt=;
scanf("%d",&tt);
for(;tt;tt--){
scanf("%d%d",&x,&y);
if(g[x][y][]==)puts("YES");
else puts("NO");
}
}
100分 动态规划
预计得分100++
实际得分100++
T1较简单,是以前做过的原题。T2看到函数递归就觉得应该和栈有关系,仔细研究,这不就是个括号序列吗,一开始以为要用双向链表,后来发现加个数组记录一下id,再加一个栈模拟退栈就好了,虽然和标解不太一样,但是A了。T3我思索良久,想过建分层图,但复杂度太高,正确性也很玄学,所以就写了个dfs,才搜了5分
今天的题都是关于栈的,发挥的还好,但我觉得T3的dfs应该再优化一下,尽量拿到更多部分分
小结
清北刷题冲刺 11-02 a.m的更多相关文章
- 清北刷题冲刺 11-03 a.m
纸牌 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- 2017-10-2 清北刷题冲刺班a.m
一道图论神题 (god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只 ...
- 2017-10-2 清北刷题冲刺班p.m
最大值 (max) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一本书,上面有很多有趣的OI问题.今天LYK看到了这么一道题目: 这里有一个长度为n ...
- 清北刷题冲刺 11-01 p.m
轮换 #include<iostream> #include<cstdio> #include<cstring> #define maxn 1010 using n ...
- 清北刷题冲刺 10-31 a.m
集合 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; ], ...
- 清北刷题冲刺 10-30 a.m
星空 #include<iostream> #include<cstdio> using namespace std; int n,m; int main(){ freopen ...
- 清北刷题冲刺 10-29 p.m
洗澡 /* 这个题不能单纯判断左括号和右括号的多少,而应该从左到右扫一遍,看应该如何配对 */ #include<iostream> #include<cstdio> #inc ...
- 清北刷题冲刺 10-28 p.m
水题(贪心) (water) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK出了道水题. 这个水题是这样的:有两副牌,每副牌都有n张. 对于第一副牌的每 ...
- 清北刷题冲刺 10-28 a.m
立方数 (cubic) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方 ...
随机推荐
- Mybatis学习--Mapper XML文件
学习笔记,选自Mybatis官方中文文档:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#insert_update_and_delete My ...
- opensource mcu
1 OpenVCS - Open Source Video Conferencing Server it is used as Multipoint Control Unit (MCU) manage ...
- H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式(包含AAC部分解析)
H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +------------ ...
- 【LeetCode】013. Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- 系列文章--8天学通MongoDB
随笔分类 - MongoDB 8天学通MongoDB——第八天 驱动实践 摘要: 作为系列的最后一篇,得要说说C#驱动对mongodb的操作,目前驱动有两种:官方驱动和samus驱动,不过我个人还是喜 ...
- 洛谷P4721 【模板】分治 FFT(生成函数+多项式求逆)
传送门 我是用多项式求逆做的因为分治FFT看不懂…… upd:分治FFT的看这里 话说这个万恶的生成函数到底是什么东西…… 我们令$F(x)=\sum_{i=0}^\infty f_ix^i,G(x) ...
- ECMAScript函数表达式
--<JavaScript高级程序设计>Chapter7总结 1.匿名函数的作用 (1)动态定义函数 var sayHi; var a=1; if (a>0) { sayHi=fun ...
- asp.net分页asp.net无刷新分页高效率分页
项目中经常会用到分页的功能类似的项目做过无数个了,今个把自己常用的分页代码分享一下. 首先说说服务端处理的代码: 下面代码中重点是分页的sql语句的写法,其中的参数@n是当前的页码,总的来说本服务端主 ...
- netty中的引导Bootstrap客户端
一.Bootstrap Bootstrap 是 Netty 提供的一个便利的工厂类, 我们可以通过它来完成 Netty 的客户端或服务器端的 Netty 初始化.下面我以 Netty 源码例子中的 E ...
- 自定义echart tooltip格式
formatter: function (tipData) { return tipData[0].name + '</br>' + '<span style="displ ...