zoukankan      html  css  js  c++  java
  • Education Round16

    A题:
    题意:给定国际象棋king的坐标,求能向几个方向移动
    分析:处理一下边界情况,其他的都是8

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <vector>
     6 #include <algorithm>
     7 #include <set>
     8 #include <map>
     9 #include <bitset>
    10 #include <cmath>
    11 #include <queue>
    12 #include <stack>
    13 using namespace std;
    14 string s;
    15 int main()
    16 {
    17     while(cin>>s)
    18     {
    19         if((s[0]!='a'&&s[0]!='h')&&(s[1]!='1'&&s[1]!='8'))
    20             cout<<"8"<<endl;
    21         else
    22         {
    23             if(s[0]=='a'||s[0]=='h')
    24             {
    25                 if(s[1]=='1'||s[1]=='8')
    26                     cout<<"3"<<endl;
    27                 else
    28                     cout<<"5"<<endl;
    29             }
    30             else
    31                 cout<<"5"<<endl;
    32         }
    33     }
    34     return 0;
    35 }
    View Code

    B题:
    题意:给定一条直线上的一些点,求到这些点距离最近的点的坐标
    分析:有推倒可以得到,我们可以把坐标先排序,如果有偶数个则取中间一个,如果有奇数个取中间一个的下一个

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <vector>
     6 #include <algorithm>
     7 #include <set>
     8 #include <map>
     9 #include <bitset>
    10 #include <cmath>
    11 #include <queue>
    12 #include <stack>
    13 using namespace std;
    14 const int maxn=300010;
    15 const int INF=1<<30;
    16 int a[maxn];
    17 int n;
    18 int main()
    19 {
    20     while(cin>>n)
    21     {
    22         for(int i=1;i<=n;i++)
    23            scanf("%d",&a[i]);
    24         sort(a+1,a+1+n);
    25         int k=n/2;
    26         if(n%2==0)
    27         cout<<a[n/2]<<endl;
    28         else
    29         cout<<a[n/2+1]<<endl;    
    30     }
    31     return 0;
    32 }
    View Code
  • 相关阅读:
    php笔记小结
    php知识总结(二)
    php知识点总结(一)
    js冒泡排序及计算其运行时间
    空中飘动的云动画
    网站建设教程:WordPress如何在虚拟主机上安装
    网站建设教程之PageAdmin建站系统的安装
    免费CMS建站系统哪个比较好?如何选择?
    网站建设之自助建站系统的选择?
    企业外贸网站制作的要求及注意事项
  • 原文地址:https://www.cnblogs.com/wolf940509/p/5797886.html
Copyright © 2011-2022 走看看