A. Pasha and Pixels

    题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵。直接模拟即可

  代码:

 #include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#define N 100010
#define M 1010
#define P 1000000007
using namespace std;
int n,m,k,i,a[N],b[N],f[M][M];
int check(int x,int xx,int y,int yy)
{
int w=;
w=f[x][y]+f[x][yy]+f[xx][y]+f[xx][yy];
if (w==) return ;else return ;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
for (i=;i<=k;i++)
scanf("%d%d",&a[i],&b[i]);
for (i=;i<=k;i++)
{
f[a[i]][b[i]]=;
if (check(a[i]-,a[i],b[i]-,b[i])) break;
if (check(a[i]-,a[i],b[i],b[i]+)) break;
if (check(a[i],a[i]+,b[i]-,b[i])) break;
if (check(a[i],a[i]+,b[i],b[i]+)) break;
}
if (i<=k)
printf("%d",i);
else
printf("");
}

B. Anton and currency you all know

  题意是给一个奇数,你可以交换其中两位,使得其变成一个偶数,并且要求这个偶数尽可能大。由于给的数字是奇数,因此必然是个位数和一个其他位上的数交换,并且交换的这个数得是偶数,如果数字全为奇数那明显不可以。如果交换的这个数大于个位,那么交换以后的数明显会比原数大,因此尽可能的选取高位的数字,使得其比个位数大,那么直接交换即可。若不存在交换的数比个位要大,说明交换后的数字一定会比原数小,那么则应选取一个位数最小的偶数,和个位交换。

代码:

 #include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#define N 100010
#define M 1010
#define P 1000000007
using namespace std;
char s[N],t;
int tmp,len,i;
int main()
{
tmp=-;
scanf("%s",s);
len=strlen(s);
for (i=;i<len-;i++)
if (s[i]%==)
{
if (s[len-]>s[i]) break;
tmp=i;
}
if (i<len-)
{
t=s[i];s[i]=s[len-];s[len-]=t;
}
else
if (tmp!=-)
{
t=s[tmp];s[tmp]=s[len-];s[len-]=t;
}
else
{
printf("-1");
return ;
}
printf("%s",s);
}

C. Anya and Ghosts

  首先需要注意这一题是允许蜡烛在0时之前点的,一时刻只能点亮一根蜡烛。要使蜡烛使用的最少,明显可以采取贪心的做法,能不放则不放,如果到了指定时刻蜡烛数目没有要求的数目,那么在放。

代码:

 #include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#define N 100010
#define M 1010
#define P 1000000007
using namespace std;
int m,t,r,i,j,L,R,v[N],w[N];
map<int,int>ma;
int main()
{
scanf("%d%d%d",&m,&t,&r);
for (i=;i<=m;i++)
scanf("%d",&w[i]);
L=;R=;
for (i=;i<=m;i++)
{
while ((L<=R)&&(v[L]<w[i])) L++;
if (R-L+<r)
for (j=r-(R-L+);j>=;j--)
{
R++;
if (ma[w[i]-j+t]==)
{
printf("-1");
return ;
}
ma[w[i]-j+t]=;
v[R]=w[i]-j+t;
if (v[R]<w[i])
{
printf("-1");
return ;
}
}
}
printf("%d",R);
}

D. Tanya and Password

  这一题可以转换成求一个欧拉通路,具体的做法每个串都转化成一条边,例如"abc"这个串,可以转换成"ab"->"bc"。也就是前两个字母视为一个节点,后两个字母视为另一个节点,然后连一条有向边。

  若有向图中存在一条欧拉通路,则(1)图联通(2)全部点的入度都等于出度或者有一个点入度=出度+1,并且还有一个点出度=入度+1。

代码:

 #include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#include<iostream>
#define N 500010
#define M 1010
#define P 1000000007
using namespace std;
map<string,int> ma;
map<int,string> o;
string s,s1,s2;
int n,i,a,b;
int p[N],tt[N],pre[N],dp,tot,rd[N],cd[N],cnt1,cnt2,st,ed,f[N];
char ans[N];
void link(int x,int y)
{
dp++;pre[dp]=p[x];p[x]=dp;tt[dp]=y;
}
int gf(int x)
{
int p,t;
p=x;
while (p!=f[p])p=f[p];
while (x!=t)
{
t=f[x];
f[x]=p;
x=t;
}
return p;
}
void dfs(int x)
{
int i,tmp=;
i=p[x];
while (i)
{
p[x]=pre[i];
dfs(tt[i]);
i=p[x];
}
tot++;ans[tot]=o[x][];
}
int main()
{
scanf("%d",&n);
for (i=;i<=n;i++)
{
cin>>s;
s1="";
s1=s1+s[]+s[];
s2="";
s2=s2+s[]+s[];
if (ma[s1]==)
{
tot++;
ma[s1]=tot;
o[tot]=s1;
f[tot]=tot;
}
if (ma[s2]==)
{
tot++;
ma[s2]=tot;
o[tot]=s2;
f[tot]=tot;
}
a=ma[s1];
b=ma[s2];
link(a,b);
rd[b]++;cd[a]++;
f[gf(a)]=gf(b);
}
for (i=;i<=tot;i++)
if (gf(i)!=gf())
{
printf("NO");
return ;
}
st=;
for (i=;i<=tot;i++)
{
if (cd[i]-rd[i]==) {
st=i;
cnt1++;
}
else
if (rd[i]-cd[i]==)
cnt2++;
else
if (cd[i]-rd[i]!=)
{
printf("NO");
return ;
}
}
if ((cnt1+cnt2==)||(cnt1*cnt2==))
{
printf("YES\n");
printf("%c",o[st][]);
tot=;
dfs(st);
for (i=tot;i>=;i--)
printf("%c",ans[i]);
}
else
printf("NO");
}

E. Arthur and Brackets

  题意是给一个n,表示有n个左括号,n个右括号,构成长度为2n的括号序列,接下来第i行给的L[i]和R[i]表示从左往右第i个左括号的对应的右括号与他的距离范围(注意给的是距离范围而不是在序列中的实际位置范围),问是否存在一个合法的括号序列,如果存在,那么随意输出一个。

  做法是dp,f[i][j]表示是否存在从第i对括号到第j对括号组成的合法括号序列,dp方程有两种情况

  (1)假设i<=k<j,如果f[i][k]=1,f[k+1][j]=1,那么很明显f[i][j]=1,因为如果两个序列是合法的,那么他们左右拼接明显也是合法的。

  (2)如果f[i+1][j]=1,那么如果要加上第i对括号后也合法,那么第i个左括号和其所对应的右括号的距离应该是(j-i)*2+1,如果这个距离在其的距离范围内,那么则可行,否则不存在这种情况。

  复杂度O(n^3)

代码:

 #include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#define N 100010
#define M 1010
#define P 1000000007
using namespace std;
int tot,f[M][M],l[M],r[M],i,j,k,L,R,z,n;
char s[N];
void dfs(int l,int r)
{
int i;
if (l>r) return;
for (i=l;i<=r-;i++)
if ((f[l][i])&&(f[i+][r]))
{
dfs(l,i);
dfs(i+,r);
return;
}
if (f[l+][r])
{
s[tot]='(';tot++;
dfs(l+,r);
s[tot]=')';tot++;
} }
int main()
{
scanf("%d",&n);
for (i=;i<=n;i++)
f[i+][i]=;
for (i=;i<=n;i++)
scanf("%d%d",&l[i],&r[i]);
for (i=;i<=n;i++)
for (j=;j<=n-i+;j++)
{
L=j;R=j+i-;
for (k=L;k<=R-;k++)
f[L][R]=(f[L][R]|(f[L][k]&f[k+][R]));
if ((f[L+][R])&&(l[j]<=*i-)&&(*i-<=r[j]))
z=;
else
z=;
f[L][R]=(f[L][R]|z);
}
if (f[][n]==)
printf("IMPOSSIBLE");
else
{
dfs(,n);
printf("%s",s);
}
}
 

Codeforces Round #288 (Div. 2)的更多相关文章

  1. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  2. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  3. Codeforces Round #288 (Div. 2) E. Arthur and Brackets

    题目链接:http://codeforces.com/contest/508/problem/E 输入一个n,表示有这么多对括号,然后有n行,每行输入一个区间,第i行的区间表示从前往后第i对括号的左括 ...

  4. Codeforces Round #288 (Div. 2)D. Tanya and Password 欧拉通路

    D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508 ...

  5. 欧拉回路/通路 Codeforces Round #288 (Div. 2)

    http://codeforces.com/contest/508/problem/D 以上是题目链接 题目大意 给n个字符串看能不能链接在一起 因为 三个三个分割 所以字符串 如abc ab作为起点 ...

  6. 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels

    题目传送门 /* 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 很挫的判断四个方向是否OK */ #include <cs ...

  7. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #288 (Div. 2) E. Arthur and Brackets 贪心

    E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input stand ...

  9. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 【Android开发学习笔记】【第十课】运动事件 之——触摸屏

    概念 触摸屏 (TouchScreen) 和 滚动球(TrackBall)是Android 中除了键盘之外的主要输入设备. 而这两个事件都可以用运动事件(MotionEvent)用于接收他们的信息 直 ...

  2. SQL Server数据库连接字符串的组成

    DB驱动程序常见的驱动程序如下: ODBC   ODBC(Open Database Connectivity,开放数据库互连)是微软公司开放服务结构(WOSA,Windows Open Servic ...

  3. 使用多种客户端消费WCF RestFul服务(四)——Jquery篇

    Jquery篇 互联网开发中少不了各类前端开发框架,其中JQUERY就是最流行之一,本篇我们就采用JQUERY来消费WCF RestFul服务,其中用到JSON基础知识,如果有想了解的朋友,请访问:& ...

  4. 一本很不错的书----DOOM启示录

    强推,所有玩游戏的和做游戏的热爱游戏的都应该看看. 摘录了一些话. 盖茨不明白,为什么啊为什么,为什么一个麦斯奎特的小公司,居然能从他手下挖走迈克尔·亚伯拉什,而且仅仅凭借几个游戏就胜过了自己的软件帝 ...

  5. pod setup》error: RPC failed; result=18, HTTP code = 200

    Try reducing the postBuffer size in the remote repository config. Follow the steps below Go to remot ...

  6. RTSP 协议分析

    RTSP 协议分析1.概述: RTSP(Real Time Streaming Protocol),实时流传输协议,是TCP/IP协议体系中的一个应用层协议,由哥伦比亚大学.网景和RealNetwor ...

  7. strlen

    char c1[] = "sdfa";//系统自动添加结束字符 \0 char c2[] = {'1','2','3'};//这样赋值的话,要自己加上结束字符 \0 printf( ...

  8. Docker 介绍以及其相关术语、底层原理和技术

    https://ruby-china.org/topics/22004 Docker是啥 Docker是一个程序运行.测试.交付的开放平台,Docker被设计为能够使你快速地交付应用.在Docker中 ...

  9. LeetCode Count Complete Tree Nodes

    原题链接在这里:https://leetcode.com/problems/count-complete-tree-nodes/ Given a complete binary tree, count ...

  10. form表单类标签汇总

    <form action="form_action.asp" method="get"> First name: <input type=&q ...