
杂题
sepNINE
it is written
展开
-
poj 3154 Graveyard 贪心
//poj 3154//sep9#include #include using namespace std;double a[2048];double b[2048];int main(){ int n,m; while(scanf("%d%d",&n,&m)==2){ for(int i=0;i<n;++i) a[i]=i*(10000.0/n); for(i原创 2015-06-30 23:40:42 · 903 阅读 · 0 评论 -
poj 3045 Cow Acrobats 贪心
//poj 3045//sep9#include #include using namespace std;struct COW{ int w,s;}cow[50012];int cmp(COW x,COW y){ return x.w+x.s>y.w+y.s; }int main(){ int n; scanf("%d",&n); for(int i=0;i<n原创 2015-11-13 16:31:56 · 426 阅读 · 0 评论 -
poj 1150 The Last Non-zero Digit 求排列数的最后非零数
//poj 1150//sep9#include using namespace std;int table[4][4]={ 6,2,4,8, 1,3,9,7, 1,7,9,3, 1,9,1,9,};int f2(int n){ if(n==0) return 0; return n/2+f2(n/2);}int f5(int n){ if(n==0) retu原创 2015-11-16 12:20:41 · 488 阅读 · 0 评论 -
poj 2527 Polynomial Remains 模拟多项式的除法
//poj 2527//sep9#include using namespace std;int a[10024];int main(){ int n,k; while(scanf("%d%d",&n,&k)==2){ if(n==-1&&k==-1) break; for(int i=0;i<=n;++i) scanf("%d",&a[i]); for(原创 2015-11-17 16:08:46 · 681 阅读 · 0 评论 -
poj 3075 Tic-Tac-Toe 五子棋模拟
//poj 3075//sep9#include #include using namespace std;int way[8][3]={ {0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8}, {0,4,8}, {2,4,6}};char s[16];bool check(char c){ for(原创 2015-12-10 09:41:54 · 1172 阅读 · 0 评论 -
poj 2361 Tic Tac Toe 五子棋模拟
//poj 2361//sep9//与poj3075的区别是在游戏中的状态也合法#include #include using namespace std;int way[8][3]={ {0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8}, {0,4,8}, {2,4,6}};char s[16];b原创 2015-12-10 10:00:22 · 1041 阅读 · 1 评论 -
poj 1240 Pre-Post-erous! 分治
//poj 1240//sep9#include using namespace std;typedef __int64 INT;char x[32],y[32];INT M;INT C(INT n,INT m){ INT ans=1; m=m>(n-m)?(n-m):m; for(INT i=1;i<=m;++i) ans=ans*(n-i+1)/i; retu原创 2015-12-11 14:50:00 · 922 阅读 · 0 评论 -
poj 2673 Kicc Wants to Move a Mountain! 模拟水题
//poj 2673//sep9#include using namespace std;int main(){ int t,x,m,d=INT_MAX; scanf("%d%d%d",&t,&x,&m); if(m==0){ printf("%d",t*x); return 0; } while(m--){ int a,b; scanf("%d%d",&a,原创 2015-11-03 12:21:00 · 562 阅读 · 0 评论 -
poj 3517 And Then There Was One 约瑟夫问题
//poj 3517//sep9#includeusing namespace std;int main(){ int n,k,m; while(scanf("%d%d%d",&n,&k,&m)==3&&(n|m|k)){ int ans=0; for(int i=2;i<n;++i) ans=(ans+k)%i; ans=(ans+m)%n; printf(原创 2015-12-12 01:37:12 · 506 阅读 · 0 评论 -
poj 1929 Calories from Fat 模拟水题
//poj 1929//sep9#include using namespace std;double tot,fat;char s[5][128];void get_value(int i,double &v,int &tag){ int p=0; v=0; while(s[i][p]='0') v=10*v+s[i][p]-'0',++p; if(s[i][p]==原创 2015-11-19 16:02:41 · 637 阅读 · 0 评论 -
poj 1009 Edge Detection 模拟
//poj 1009//sep9#include #include using namespace std;const int maxN=1024;struct RLE{ int v,pos; }rle_in[maxN],rle_out[maxN*8];int n,m,p,q,sum;int cmp(RLE x,RLE y){ return x.pos<y.pos;原创 2015-10-23 13:11:00 · 464 阅读 · 0 评论 -
poj 2265 Bee Maja 模拟计数
//poj 2265//sep9#include using namespace std;const int maxN=100000;int f[maxN+10];int main(){ int n; f[0]=1; for(int i=1;i<maxN;++i) f[i]=6*i+f[i-1]; while(scanf("%d",&n)==1){ int i;原创 2015-11-06 13:12:52 · 692 阅读 · 0 评论 -
poj 1299 Polar Explorer 水题
//poj 1299//sep9#include using namespace std;const double pi=3.14159;char s[32];int main(){ while(scanf("%s",s)==1&&strcmp(s,"ENDOFINPUT")!=0){ double x,y,z; scanf("%lf%lf%lf",&x,&y,&z);原创 2015-11-05 11:45:31 · 658 阅读 · 0 评论 -
poj 3307 Smart Sister 打表解因子生成数问题
题意:给i,求由仅以2,3,5,7为因子的数中第i个是多少。分析:打表。代码://poj 3307//sep9#include using namespace std;typedef unsigned __int64 INT;const int maxL=66062;INT a[maxL+10];INT min4(INT a,INT b,INT c,INT d)原创 2015-06-30 21:04:52 · 842 阅读 · 0 评论 -
poj 1021 2D-Nim 模拟
题意:给两个平面,每个平面上有一些点,相邻的点可构成点集,为两个平面内的点集是够都对应相似。两个点集相似是指经过对称或旋转或平移后相等。分析:直接模拟判断。代码://poj 1021//sep9#include #include #include using namespace std;int w,h,n;int g[128][128];int vis[128]原创 2015-07-01 12:28:19 · 958 阅读 · 0 评论 -
poj 4016 Flat 水题
#include using namespace std;int main(){ int n,c,area=0,bed_area=0,bal_area=0; scanf("%d%d",&n,&c); while(n--){ int x; char s[16]; scanf("%d%s",&x,s); area+=x; if(strcmp(s,"bedroom")=原创 2015-07-02 11:31:31 · 954 阅读 · 0 评论 -
poj 4014 Dice 贪心
//poj 4014//sep9#include #include using namespace std;int n;struct DICE{ int ids; int num; int a[128];}d[1024];int cmp1(DICE x,DICE y){ return x.num<y.num;}int cmp2(DICE x,DICE y){原创 2015-07-02 22:29:59 · 883 阅读 · 0 评论 -
poj 1941 The Sierpinski Fractal 递归
//poj 1941//sep9#include using namespace std;const int maxW=2048;const int maxH=1024;int pow2[32];char g[maxH+10][maxW+10];void print(int x,int y,int n){ if(n==1){ g[x][y+1]='/'; g[x][y+原创 2015-07-07 08:05:38 · 2459 阅读 · 0 评论 -
poj 3276 Face The Right Way 翻转问题的灵活处理
题意:给一个0,1序列,每次连续翻转k个,求翻转m次将序列全置0的最优二元组(k,m)。分析:题意说是要优先优化m,但不一定要优先枚举m,可以先枚举k再在内循环中处理。这题关键是把独立关系转化为依赖关系,每位与前面一样为0,不一样为1。这样翻转一位i时,只需改变i+k,不用改变i,i+1,i+2,i+k-1。代码://poj 3276//sep9//n^2#include原创 2015-09-28 17:51:31 · 442 阅读 · 0 评论 -
poj 1700 Crossing River 贪心
题意:有n个人要坐船过河,每个人需要的时间已知,有一条最多容纳两个人的船,两个人坐船的时间为两人中的较大值,求所有人过河的最少时间。分析:设4个人分别要a分析://poj 1700//sep9#include #include using namespace std;int n;int a[1024];int main(){ int cases; scan原创 2015-10-02 14:40:38 · 476 阅读 · 0 评论 -
poj 2940 Wine Trading in Gergovia 贪心+扫描
//poj 2940//sep9#include using namespace std;typedef __int64 INT;int main(){ int n; while(scanf("%d",&n)==1&&n){ INT ans=0,sum=0,t; for(int i=0;i<n;++i){ scanf("%I64d",&t); ans+=sum原创 2015-11-05 14:55:48 · 411 阅读 · 0 评论 -
poj 1362 Skew Binary 进制转换
//poj 1362//sep9#include using namespace std;int weight[36];int skew[36],flag;void print(int x){ if(flag==1) printf(","); printf("%d",x); flag=1;}int main(){ for(int i=0;i<30;++i)原创 2015-11-05 13:12:37 · 1518 阅读 · 0 评论 -
poj 1302 Blue Gene, Jr. 递归
//poj 1302//sep9#include using namespace std;char s[32];int n;int f(int cur){ if(cur==n||s[cur]=='0'){ return 0; } if(s[cur]>='A'&&s[cur]<='Z'){ int t=f(cur+1); s[cur]=t%10+'0'; retu原创 2015-11-26 16:00:09 · 584 阅读 · 0 评论 -
poj 1353 Color Change of Go Game Pieces 模拟
//poj 1353//sep9#include using namespace std;int n,m,k;int a[2][256];int main(){ while(scanf("%d,%d,%d",&n,&m,&k)==3){ int *crt=a[0],*nxt=a[1]; for(int i=0;i<n;++i) if(i<m) crt[i]=0;原创 2015-11-26 16:49:08 · 582 阅读 · 0 评论 -
poj 1741 Tree 树上的分治+求树的重心
//poj 1741//sep9#include #include #include using namespace std;const int MAXN=10024;int ans,n,K,e;int subtree_size[MAXN],head[MAXN];bool centroid[MAXN];struct EDGE{ int v,w,nxt;}edge[2*MA原创 2015-11-26 22:42:53 · 457 阅读 · 0 评论 -
poj 2054 Color a Tree 贪心
//poj 2054//sep9#include using namespace std;const int MAXN=1024;int n,root,e_cnt;int vis[MAXN],num[MAXN],c[MAXN],prev[MAXN];int head[MAXN],adj[MAXN],next[MAXN]; int find_root(){ double maxx原创 2016-08-01 22:27:22 · 593 阅读 · 0 评论 -
poj 1027 The Same Game 模拟
//poj 1027//sep9#include using namespace std;int leave,score;int rx,ry,n,cnt;char g[20][20];bool vis[20][20];int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};bool inGraph(int x,int y){ return x>=原创 2016-08-31 20:05:52 · 653 阅读 · 0 评论 -
poj 3404 Bridge over a rough river 贪心
//poj 3404//sep9#include #include using namespace std;int n;int a[128];int main(){ scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); sort(a+1,a+n+1); int sum=0; while(n>0){原创 2016-08-31 21:53:19 · 581 阅读 · 0 评论 -
poj 1099 Square Ice 模拟
//poj 1099//sep9#include using namespace std;const int MAXM=12;char g[4*MAXM+5][4*MAXM+5];int mat[MAXM+5][MAXM+5];int m;void solve(){ memset(g,' ',sizeof(g)); for(int i=0;i<4*m-1;++i) g[原创 2016-12-03 15:09:54 · 595 阅读 · 0 评论 -
poj 1053 Set Me 枚举水题
//poj 1053//sep9#include using namespace std;struct Card{ char characters[8]; }tableau[16];bool judge(int p,int i,int j,int k){ if(tableau[i].characters[p]==tableau[j].characters[p]) if(t原创 2017-01-20 09:59:35 · 647 阅读 · 0 评论 -
poj 1120 A New Growth Industry 模拟
//poj 1120//sep9#include using namespace std;const int SIZE=20;int D[SIZE+4],mat[SIZE+4][SIZE+4],sum[SIZE+4][SIZE+4];int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};char ch[4]={'.','!','X','#'};int原创 2017-07-13 22:37:37 · 584 阅读 · 0 评论 -
poj 1176 Party Lamps 模拟
//poj 1176//sep9#include #include #include using namespace std;const int MAXN=128;int N,C,limit[MAXN],tmp[MAXN];string pass_string[20];string get_string(){ string res; for(int i=0;i<N;++i原创 2017-07-15 02:30:10 · 570 阅读 · 0 评论 -
poj 1033 Defragment 模拟+递归
//poj 1033//sep9#include using namespace std;const int MAXN=10024;int a[MAXN],vis[MAXN],N,K;int zero_pos,flag;void dfs(int i){ if(a[i]==i||a[i]==0) return; if(vis[a[i]]==1){ printf("%d %原创 2017-07-31 22:36:24 · 504 阅读 · 0 评论 -
poj 1145 Tree Summing 栈+模拟
题意:给一个数a和一棵带权树T,判断T根到叶子的若干路径的权和中是否有和a相等的。分析: 栈用来表达式求值有两种办法,一是将表达式转为后序再求值,二是利用单调符号栈一次扫描。单调符号栈一次扫描法求值时维护单调符号栈(栈中总是优先级低的符号在下,‘(’在栈外优先级最高,栈中优先级最低,‘)’在栈外优先级最低,不可能出现在栈中)。先搞清楚表达式求值的单调符号栈一次扫描法这题就容原创 2017-07-27 12:57:51 · 446 阅读 · 0 评论 -
poj 2271 HTML 模拟
//poj 2271//sep9#include #include using namespace std;int main(){ string s; int i,cnt=0; while(cin>>s){ if(s==""){ cout<<endl; cnt=0; }else if(s==""){ if(cnt) cout<<endl;原创 2016-05-17 16:27:53 · 785 阅读 · 0 评论 -
poj 2612 Mine Sweeper 简单模拟
//poj 2612//sep9#include using namespace std;int n;int cnt[16][16];char mine[16][16];char touch[16][16];int dx[8]={-1,0,1,-1,1,-1,0,1};int dy[8]={1,1,1,0,0,-1,-1,-1};int main(){ memset(cnt原创 2016-04-20 16:56:58 · 834 阅读 · 0 评论 -
poj 1126 Simply Syntax 右线性文法的归约
题意:给字符串s判断是否符合文法X->CXX|DXX|EXX|IXX|NX|p~z。分析:线性文法直接归约就好。代码;//poj 1126//sep9#include #include using namespace std;char s[300];bool solve(){ _strrev(s); int cnt=0; for(int i=0;s[i];+原创 2016-04-28 14:29:20 · 946 阅读 · 0 评论 -
poj 1063 Flip and Shift 冒泡排序的扩展运用
题意:给一个0,1组成的环,问是否可以通过交换间隔为1的两个数使所有1相邻。分析:冒泡排序就是交换相邻2个数可以把任何序列排成升序,用这一性质奇偶讨论下就好。代码://poj 1063//sep9#include using namespace std;int main(){ int cases; scanf("%d",&cases); while(cases原创 2015-12-14 11:53:38 · 556 阅读 · 0 评论 -
poj 2565 Average is not Fast Enough! 水题
//poj 2565//sep9#include using namespace std;char s[16];int get_second(){ if(s[0]=='-') return -1; int H,M,S; H=s[0]-'0'; M=10*(s[2]-'0')+s[3]-'0'; S=10*(s[5]-'0')+s[6]-'0'; return H*360原创 2015-12-15 20:01:19 · 585 阅读 · 0 评论 -
poj 3340 Barbara Bennett's Wild Numbers 递归
//poj 3340 //sep9#include using namespace std;typedef __int64 INT;int n;char a[16],b[16];INT dfs(int cur,int pre_state){ if(cur==n){ if(pre_state>0) return 1; else return 0; } i原创 2015-12-18 16:22:10 · 605 阅读 · 0 评论