• API
• FAQ
• Tools
• Archive
daily pastebin goal
51%
SHARE
TWEET

# Bebek Istimewa

a guest Sep 17th, 2011 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <cstdio>
2. #include <algorithm>
3. #include <vector>
4. #include <cmath>
5. using namespace std;
6. #define R(i,_a,_b) for(int i=int(_a);i<int(_b);i++)
7. #define RV(i,_a,_b) for(int i=int(_a);i>=int(_b);i--)
8.
9. int num,nkandang,nbuka;
10. int steps[1002];
11. bool a[1002][10002];
12.
13. int main() {
14.     scanf("%d%d", &nkandang, &nbuka);
15.     R(i,1,nbuka+1) {
16.         scanf("%d", &num);
17.         a[i][num]=1;
18.     }
19.     R(i,1,nbuka+1) {
20.         R(j,1,nkandang+1) {
21.             if(i==1 and a[i][j]!=1) {
22.                 a[i][j]=0;
23.             } else {
24.                 if(j>1 and a[i-1][j-1]!=1 and a[i][j]!=1) {
25.                     a[i][j]=0;
26.                 } else
27.                 if(j<nkandang and a[i-1][j+1]!=1 and a[i][j]!=1) {
28.                     a[i][j]=0;
29.                 } else a[i][j]=1;
30.             }
31.         }
32.     }
33.
34.     int akhir=0;
35.     R(i,1,nkandang+1) if(a[nbuka][i] == 0) { akhir=i; break; }
36.
37.     if( akhir == 0) printf("menyerah\n");
38.     else{
39.         RV(i,nbuka,2) {
40.             if( akhir >1 and a[i-1][akhir-1]==0) {
41.                 steps[i]=akhir;
42.                 akhir-=1;
43.             } else if(akhir <nkandang and a[i-1][akhir+1]==0) {
44.                 steps[i]=akhir;
45.                 akhir+=1;
46.             }
47.         }
48.         steps[1]=akhir;
49.         R(i,1,nbuka+1) printf("%d\n", steps[i]);
50.     }
51.     return 0;
52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top