[ZOJ 3839] Poker Face (递归)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3839

题目大意:画脸。。每张脸是上一个脸倒过来加上眼睛。。

注意n<8时停止,被这个坑惨了- -以为是0停止。。

递归,然后去推坐标公式。。

  1 #include <cstdio>
  2 #include <algorithm>
  3 #include <cstring>
  4 #include <vector>
  5 using namespace std;
  6 typedef long long LL;
  7 typedef pair<int,int> PII;
  8 typedef vector<int> vec;
  9 typedef vector<vec> mat;
 10 #define AA first
 11 #define BB second
 12
 13 char s[2000][2000];
 14
 15 void solve(int x,int y,int si,bool seq){
 16 //    printf("[solve]:x=%d,y=%d,si=%d\n",x,y,si);
 17     if( si==8 ){
 18 //        return;
 19         if( seq ){
 20             for(int i=x;i<x+si;i++){
 21                 if( i==x||i==x+si-1){
 22                     for(int j=y;j<y+si;j++){
 23                         s[i][j] = ‘*‘;
 24                     }
 25                 } else {
 26                     for(int j=y;j<y+si;j++){
 27                         if( (i>=x+1&&i<=x+3)&&(j<=y+2||(j>=y+5&&j<=y+7)) ) s[i][j] = ‘*‘;
 28                         else if( i==x+4&&(j==y||(j>=y+2&&j<=y+5)||j==y+7) ) s[i][j] = ‘*‘;
 29                         else if( (i==x+5||i==x+6)&&(j==y||j==y+7||j==y+2||j==y+5) ) s[i][j] = ‘*‘;
 30                         else s[i][j] = ‘ ‘;
 31                     }
 32                 }
 33             }
 34         } else {
 35             for(int i=x;i>x-si;i--){
 36                 if( i==x||i==x-si+1 ){
 37                     for(int j=y;j>y-si;j--){
 38                         s[i][j] = ‘*‘;
 39                     }
 40                 } else {
 41                     for(int j=y;j>y-si;j--){
 42                         if( (i<=x-1&&i>=x-3)&&(j>=y-2||(j<=y-5&&j>=y-7)) ) s[i][j] = ‘*‘;
 43                         else if( i==x-4&&(j==y||(j<=y-2&&j>=y-5)||j==y-7) ) s[i][j] = ‘*‘;
 44                         else if( (i==x-5||i==x-6)&&(j==y||j==y-7||j==y-2||j==y-5) ) s[i][j] = ‘*‘;
 45                         else s[i][j] = ‘ ‘;
 46                     }
 47                 }
 48             }
 49         }
 50         return;
 51     }
 52     if( seq ){
 53         for(int i=x;i<x+si;i++ ){
 54             if( i==x||i==x+si-1 ){
 55                 for(int j=y;j<y+si;j++){
 56                     s[i][j] = ‘*‘;
 57                 }
 58             } else {
 59                 for(int j=y;j<y+si;j++){
 60                     if( j==y||j==y+si-1 ) s[i][j] = ‘*‘;
 61                     else if( (i==x+si/8||i==x+si/8+si/4)&&((j>=y+si/8&&j<=y+si/8+si/4-1)||(j<=y+si-si/8-1&&j>=y+si-si/8-si/4)) ) {
 62                         s[i][j] = ‘*‘;
 63                     }
 64                     else if( (i>x+si/8&&i<x+si/8+si/4)&&(j==y+si/8||j==y+si/8+si/4-1||j==y+si-si/8-1||j==y+si-si/8-si/4) ) s[i][j] = ‘*‘;
 65                     else s[i][j] = ‘ ‘;
 66                 }
 67             }
 68         }
 69         solve(x+si-1,y+si-si/4-1,si/2,!seq);
 70     } else {
 71         for(int i=x;i>x-si;i-- ){
 72             if( i==x||i==x-si+1 ){
 73                 for(int j=y;j>y-si;j--){
 74                     s[i][j] = ‘*‘;
 75                 }
 76             } else {
 77                 for(int j=y;j>y-si;j--){
 78                     if( j==y||j==y-si+1 ) s[i][j] = ‘*‘;
 79                     else if( (i==x-si/8||i==x-si/8-si/4)&&((j<=y-si/8&&j>=y-si/8-si/4+1)||(j>=y-si+si/8+1&&j<=y-si+si/8+si/4)) ) {
 80                         s[i][j] = ‘*‘;
 81                     }
 82                     else if( (i<x-si/8&&i>x-si/8-si/4)&&(j==y-si/8||j==y-si/8-si/4+1||j==y-si+si/8+1||j==y-si+si/8+si/4) ) s[i][j] = ‘*‘;
 83                     else s[i][j] = ‘ ‘;
 84                 }
 85             }
 86         }
 87         solve(x-si+1,y-si+si/4+1,si/2,!seq);
 88     }
 89 }
 90
 91 int n;
 92
 93 int main(){
 94     while( ~scanf("%d",&n) ){
 95         if(n < 8)break;
 96         solve(0,0,n,true);
 97         for(int i=0;i<n;i++){
 98             s[i][n] = ‘\0‘;
 99             //for(int j=0;j<n;j++){
100                 printf("%s\n",s[i]);
101           //  }
102            // puts("");
103         }
104         puts("");
105     }
106 //    solve(31,31,32,false);
107
108     return 0;
109 }
时间: 2024-10-05 05:01:56

[ZOJ 3839] Poker Face (递归)的相关文章

ZOJ 1111 Poker Hands --复杂模拟

昨天晚上写的,写了一个多小时,9000+B,居然1A了,爽. 题意:玩扑克,比大小.规则如下: 题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小),级别从高到低依次为:1.同花顺:牌面一样,只比较最大的看谁大,一样大则平手2.四条:四个一样的,看这四个一样的中谁大谁赢3.葫芦:三条+一对,看三条中谁的牌面大4.同花:都是同花就按从大到小比较,看谁的更大5.顺子:都是顺子看最大的谁大,一样则平手6.三条:三条看三条中谁的牌面大7.两对: 两对就看谁的对

ZOJ 1111 Poker Hands

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1111 A poker hand consists of 5 cards dealt from the deck. Poker hands are ranked by the following partial order from lowest to highest High Card. Hands which do not fit any higher cat

ZOJ Monthly, November 2014

做了一次月赛,没想到这么难,加上后来补上的题目也只有3个题.第一名也只有4个题啊啊啊啊~.其中两道还是水题.留坑慢慢补上来. 3832 Tilt Cylinder 给定如图所示有盖圆柱体,R,H,水面高度h,倾角a,求水得体积. 分析:明显的数值积分题,这样考虑.圆下底面即A点与地面高度lim1, 圆上底面一点B与地面高度lim2,h所处的范围进行讨论从而确定积分几何体的两边的高度.我们积分的几何体应该是一个圆柱体被削掉一部分了. h>lim1时,几何体左半部分可以减掉一个圆柱,对剩下部分积分,

poj 2246 递归 zoj 1094

#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>#include <cmath>#include <stack>using namespace std;struct node{ int m,n; // bool f;};node hash[200];char s[1000];int main(){ int i,n,sum; char

zoj 3640 Help Me Escape (概率dp 递归求期望)

题目链接 Help Me Escape Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.  

zoj 3229 dinic算法的非递归实现以及有上下界的有源汇的网络流的最大流的求解

Shoot the Bullet Time Limit: 2 Seconds      Memory Limit: 32768 KB      Special Judge Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies, youkai(phantoms)

ZOJ 4063 - Tournament - [递归][2018 ACM-ICPC Asia Qingdao Regional Problem F]

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4063 Input Output Sample Input 2 3 1 4 3 Sample Output Impossible 2 1 4 3 3 4 1 2 4 3 2 1 题意: 说现在有 $n$ 个人打比赛,要你安排 $k$ 轮比赛,要求每轮每个人都参加一场比赛. 所有轮次合起来,任意一对人最多比赛一场. 且对于任意的第 $i,j$ 轮,若 $a,b$ 在

ZOJ 1457 Prime Ring Problem(dfs+剪枝)

?? Prime Ring Problem Time Limit: 10 Seconds      Memory Limit: 32768 KB A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime

【求无向图的桥,有重边】ZOJ - 2588 Burning Bridges

模板题——求割点与桥 题意,要使一个无向图不连通,输出必定要删掉的边的数量及其编号.求桥的裸题,可拿来练手. 套模板的时候注意本题两节点之间可能有多条边,而模板是不判重边的,所以直接套模板的话,会将重边也当做桥输出,因此要在判断桥的时候加一个判断,即当且仅当两点之间仅有一条边,且满足dfn[cur] < low[i],(cur, i)才是桥. 另外本题节点数为105,用邻接矩阵的话会内存超限,所以我用了了一个multiset存储边及其编号. 代码如下: 1 #include<cstdio>