1. 程式人生 > >【題解】 bzoj1088: [SCOI2005]掃雷Mine (神奇的做法)

【題解】 bzoj1088: [SCOI2005]掃雷Mine (神奇的做法)

真的 復制 pac bre com www. con urn 一個

bzoj1088,懶得復制,戳我戳我

Solution:

  • 其實這個有個結論,答案只會有\(0\),\(1\),\(2\)三種(我真的是個弱雞,這個都想不到)
  • 然後我們假設第一個就可以推出所有的狀態(顯然)
  • 沒了,and 我真的菜

Code:

//It is coded by Ning_Mew on 5.6
#include<bits/stdc++.h>
using namespace std;

const int maxn=1e4+7;

int n,a[maxn];
int ans=0;
int ch[maxn];

int main(){
  scanf("%d",&n);
  for
(int i=1;i<=n;i++)scanf("%d",&a[i]); bool endd=true; memset(ch,0,sizeof(ch)); ch[1]=1; for(int i=2;i<=n;i++){ if(ch[i-1]+ch[i-2]==a[i-1])ch[i]=0; else{ if(ch[i-1]+ch[i-2]==a[i-1]-1)ch[i]=1; else {endd=false;break;} } } if(endd&&ch[n-1]+ch[n]==a[n])ans++; endd=true
; memset(ch,0,sizeof(ch)); ch[1]=0; for(int i=2;i<=n;i++){ if(ch[i-1]+ch[i-2]==a[i-1])ch[i]=0; else{ if(ch[i-1]+ch[i-2]==a[i-1]-1)ch[i]=1; else {endd=false;break;} } } if(endd&&ch[n-1]+ch[n]==a[n])ans++; printf("%d\n",ans); return 0; }

【題解】 bzoj1088: [SCOI2005]掃雷Mine (神奇的做法)