zoukankan      html  css  js  c++  java
  • Codeforces Round #217 (Div. 2) 解题报告

    Problem A Rook, Bishop and King

    题目要求:在国际象棋棋盘上给你一个起始点一个终点。让你求车,象,国王从起始点到终点最短走的步数。

    做法很简单三个公式,具体看代码吧。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <utility>
     7 #include <vector>
     8 #include <queue>
     9 #include <stack>
    10 
    11 using namespace std;
    12 
    13 int x1, y1, x2, y2;
    14 
    15 inline int abs(int x){return x>0?x:-x;}
    16 
    17 int solve1()
    18 {
    19     if(x1==x2 && y1==y2)return 0;
    20     if(x1==x2 || y1==y2)return 1;
    21     return 2;
    22 }
    23 
    24 int solve2(){
    25     if((x1+x2+y1+y2)%2==1 || (x1==x2 && y1==y2))return 0;
    26     if(x1+y1==x2+y2)return 1;
    27     if(x1+(9-y1)==x2+(9-y2))return 1;
    28     return 2;
    29 }
    30 
    31 int solve3(){
    32     return max(abs(x1-x2),abs(y1-y2));
    33 }
    34 
    35 int main()
    36 {
    37 //    freopen("in.txt", "r", stdin);
    38 
    39     while(cin >> x1 >> y1 >> x2 >> y2){
    40         printf("%d ", solve1());
    41         printf("%d ", solve2());
    42         printf("%d
    ", solve3());
    43     }
    44     return 0;
    45 }
    View Code

    Problem B Berland Bingo

    题目要求:有若干个人每人手中有一些卡片,然后开始报数,没报一个数。拥有这个数卡片的人可以把卡片划掉。当一个人手上所有的卡片都划掉了。就算那个人赢了。如果两个人手上的卡片一起没有那没有人赢。问你最好的情况下第i个人会不会赢。

    主要是对于一个人手上的卡片,遍历所有其他人的查看事都有人的卡片是这个人卡片的子集。若有则不会他赢了。

    代码如下:

     1 #include <iostream>
     2 #include <fstream>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <cstdlib>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <utility>
     9 #include <vector>
    10 #include <queue>
    11 #include <stack>
    12 #define INF 0x7fffffff
    13 #define ll long long
    14 #define eps 1e-6
    15 
    16 using namespace std;
    17 
    18 int n, m[110], num[110][110], flag1[110], flag2[110];
    19 
    20 bool judge(int x, int b){
    21     memset(flag1, 0 ,sizeof flag1);
    22     memset(flag2, 0 ,sizeof flag2);
    23     for(int i=0; i<m[x]; i++){
    24         flag1[num[x][i]] = 1;
    25     }
    26     for(int i=0; i<m[b]; i++){
    27         flag2[num[b][i]] = 1;
    28     }
    29     for(int i=0; i<101; i++){
    30         if(flag1[i]==0 && flag2[i])return true;
    31     }
    32     return false;
    33 }
    34 
    35 int main()
    36 {
    37 //    freopen("in.txt", "r", stdin);
    38 
    39     while(scanf("%d", &n)!=EOF){
    40         for(int i=0; i<n; i++){
    41             scanf("%d", &m[i]);
    42             for(int j=0; j<m[i]; j++){
    43                 scanf("%d", &num[i][j]);
    44             }
    45         }
    46         for(int i=0; i<n; i++){
    47             int flag = 1;
    48             for(int j=0; j<n; j++){
    49                 if(i!=j && judge(i,j)==false){
    50                     flag = 0;break;
    51                 }
    52             }
    53             if(flag)printf("YES
    ");
    54             else printf("NO
    ");
    55         }
    56     }
    57     return 0;
    58 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    InfluxDB执行语句管理(query management)
    InfluxDB数据备份和恢复方法,支持本地和远程备份
    WordPress多本小说主题–WNovel主题发布,十分钟搭建小说站! 现已更新至1.2版本
    InfluxDB安装后web页面无法访问的解决方案
    Influxdb原理详解
    InfluxDB学习之InfluxDB连续查询(Continuous Queries)
    InfluxDB学习之InfluxDB数据保留策略(Retention Policies)
    InfluxDB学习之InfluxDB的HTTP API查询操作
    玩游戏,王者荣耀,记录
    开源抓包工具PowerSniff(支持lua,c语言作为脚本实时分析)
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3463272.html
Copyright © 2011-2022 走看看