Educational Codeforces Round 16

时间:2024-01-21 17:30:09

A. King Moves

water。= =。

 #include <cstdio>
 ,,,,,-,-,-};
 ,-,,,-,,,-,};
 #define judge(x,y) x >= 1 && x <= 8 && y >= 1 && y <= 8
 int main()
 {
     char t;
     ;
     scanf("%c%d", &t, &y);
     x = t - ;
     ; i < ; i++)
     {
         int fx = x + dx[i], fy = y + dy[i];
         if(judge(fx,fy))    cnt++;
     }
     printf("%d\n", cnt);
     ;
 }

B. Optimal Point on a Line

题目大意:给你n个坐标,找一个点到n个点的距离之和最小,如果有多解,选最左的。

这个感觉就是一道初中数竞题嘛。。那时候好像是一个区间?求的是。

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
 * 1e5 + ;
int x[maxn];
int main()
{
    int n;
    scanf("%d", &n);
    ; i < n; i++)
        scanf("%d", &x[i]);
    sort(x, x + n);
    printf()/ ]);
    ;
}

C. Magic Odd Square(基础构造)

题目大意:给你一个奇数n,然后输出一个幻方什么的?

昂。幻方的解法,组合数学的书里有,翻来覆去就解出来了,很酷。

然后这题好像是个找规律。。你就会发现有块区域放奇数,有一块放偶数就行了。。

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
 * 1e5 + ;
int x[maxn];
int main()
{
    , even = ;
    scanf("%d", &n);
    ) / ;
    ; i <= n; i++)
    {
        ; j <= n; j++)
        {
            )
            {
                printf("%d%c", odd, j == n ? '\n' : ' ');
                odd +=;
            }
            else
            {
                printf("%d%c", even, j == n ? '\n' : ' ');
                even +=;
            }
        }
    }
    ;
}

D

E

F