hackerrank_Permutation game
来源:互联网 发布:木弹弓制作过程和数据 编辑:程序博客网 时间:2024/05/16 08:22
https://www.hackerrank.com/challenges/permutation-game
面包大大给的题目,想了两个多小时还是人家给我的想法T_T,太弱了,想到了LIS,图论之类的,但是都没能实现,最后还是用的暴力,求解:如果n>32之后,这个题怎么做?
如果牛牛们有想法,请评论给我,谢谢!
#include<iostream>#include<cstring>using namespace std;bool flag[3000000];int main(){ int n; int t; cin>>t; int a[15]; while(t--) { memset(flag,0,sizeof(flag)); cin>>n; for (int i=0; i<n; i++) cin>>a[i]; for (int i=0; i<=n; i++) flag[1<<i]=true; for (int i=1; i<(1<<n); i++) { if (flag[i]) continue; int temp1=-1; bool flag_inc=true; for (int k=0; (1<<k)<=i; k++) { if (!(i&(1<<k))) continue; if (a[k]<=temp1) { flag_inc=false; break; } else temp1=a[k]; } if (flag_inc) { flag[i]=true; continue; } bool flag_worl=false; for (int j=0; (1<<j)<=i; j++) { int temp=i; if (temp&(1<<j)) temp-=(1<<j); if (flag[temp]) { flag_worl=true; break; } } if (flag_worl) flag[i]=false; else flag[i]=true; } if (flag[(1<<n)-1]) cout<<"Bob"<<endl; else cout<<"Alice"<<endl; } return 0;}
0 0
- hackerrank_Permutation game
- game
- game
- game
- game...
- Game
- Game
- Game
- Game
- game
- Game
- Game
- game
- game
- Game
- GAME
- Game
- Game
- Android中shape的使用
- Rstudio shortcuts
- 咋样才让不审核~~~~
- OpenCV 实践程序16——提取视频每一帧及用多张图片合成视频
- 汇编指令b和bl区别
- hackerrank_Permutation game
- Extjs4.2进阶--完整前后台交互带数据库(带源码)
- javascript获取URL参数
- iOS linker command failed with exit code 1 (use -v to see invocation)错误
- [Leetcode]Next Permutation
- [C++]LeetCode: 34 Combination Sum II
- 就从今天开始吧
- 数据采集系统(数据调查)学习总结(四)
- 离散对数计算的Sherwood 算法