BZOJ2990 : [Ontak2010]Keyboard

考虑从$(1,1)$开始搜索移动方案,每次移动坐标的变化量都是$2$。

如果构成了环,那么环的周长肯定是偶数。

考虑这个环一定要被若干个骨牌覆盖,且还有一个位置是空的。

所以得出环的周长是奇数,矛盾,因此这个搜索不会搜出环,从而会得到一棵有根树。

那么答案就是所有关键点加上根节点形成的虚树的边总长$\times 2-$离根最远的关键点到根的距离,DP即可。

时间复杂度$O(nm)$。

#include<cstdio>
const int N=75,M=1230;
char s[N],a[N][N];
int n,m,cnt,i,j,x,y,z,ans,id[N][N],is[M],g[M],nxt[M],v[M],f[M];
inline bool check(char x){return x==‘a‘||x==‘e‘||x==‘i‘||x==‘o‘||x==‘u‘||x==‘y‘;}
void dfs(int x,int y,int z,int u){
  if(x<1||x>n||y<1||y>m)return;
  int o=id[x][y];
  v[o]=1;
  if(u)nxt[o]=g[u],g[u]=o;
  if(z!=2&&a[x][y+1]==‘-‘)dfs(x,y+2,1,o);
  if(z!=1&&a[x][y-1]==‘-‘)dfs(x,y-2,2,o);
  if(z!=4&&a[x+1][y]==‘|‘)dfs(x+2,y,3,o);
  if(z!=3&&a[x-1][y]==‘|‘)dfs(x-2,y,4,o);
}
void dp(int x){
  for(int i=g[x];i;i=nxt[i]){
    dp(i);is[x]+=is[i];
    if(is[i]){
      ans+=2;
      if(f[i]>=f[x])f[x]=f[i]+1;
    }
  }
}
int main(){
  scanf("%d%d",&n,&m);
  for(i=1;i<=n;i+=2)for(j=1;j<=m;j+=2)id[i][j]=++cnt;
  for(i=1;i<=n;i++)for(scanf("%s",s+1),j=1;j<=m;j++)is[id[i][j]]|=check(s[j]);
  for(i=1;i<=n;i++)scanf("%s",a[i]+1);
  dfs(1,1,0,0);
  for(i=0;i<=cnt;i++)if(is[i]&&!v[i])return puts("NIE"),0;
  dp(1);
  return printf("%d",ans-f[1]),0;
}

  

时间: 2024-09-30 20:55:03

BZOJ2990 : [Ontak2010]Keyboard的相关文章

《linux 内核完全剖析》 keyboard.S 部分代码分析(key_map)

keyboard.S 部分代码分析(key_map) keyboard中间有这么一段,我一开始没看明白,究竟啥意思 key_map: .byte 0,27 .ascii "1234567890-=" .byte 127,9 .ascii "qwertyuiop[]" .byte 13,0 .ascii "asdfghjkl;'" .byte '`,0 .ascii "\\zxcvbnm,./" .byte 0,'*,0,32

Mousetrap - a simple library for handling keyboard shortcuts in Javascript

Mousetrap is a simple library for handling keyboard shortcuts in Javascript. It is around 2kb minified and gzipped and 4.5kb minified, has no external dependencies, and has been tested in the following browsers: Internet Explorer 6+ Safari Firefox Ch

uva - Broken Keyboard (a.k.a. Beiju Text)(链表)

11988 - Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problemwith the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed(internally).Yo

PAT-ADVANCED-1084-Broken Keyboard

On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen. Now given a string that you are supposed to type, and the string that you actually type out, p

UVa11988:Broken Keyboard

Description Broken KeyboardYou're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem with the keyboard is that sometimes the "home" key gets automatically pressed (internally). You're not aware of this iss

6754&#160;Keyboard of a Mobile Telephone

/*实践再次说明ch=getchar()的速度非常慢*/ /*大水题,不解释*/ #include<stdio.h> #include<string.h> int main() { int i,j,n,count; int a[150]; char ch,s[210]; j=1; for(i=97; i<=114; i++) { if(j>3) j=1; a[i]=j; j++; } a[115]=4; a[116]=1; a[117]=2; a[118]=3; a[1

UVA11988 Broken Keyboard (a.k.a. Beiju Text)【数组模拟链表】

Broken Keyboard (a.k.a. Beiju Text) You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem with the keyboard is that sometimes the "home" key or the "end" key gets automatically pressed (inter

Keyboard input

Keyboard input Python provides a build-in function called raw_input (in version 2.x) that gets input from the keyboard. In Python 3.x we use input(). When this function is called, the program stops and waits for the user to type something. When the u

500. Keyboard Row

Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. Example 1: Input: ["Hello", "Alaska", "Dad", "Peace"] Output: ["A