关闭

Educational Codeforces Round 16

标签: codeforces
198人阅读 评论(0) 收藏 举报
分类:

抽空做了一下这些题。。。F题真的是不会了。。。

A. King Moves

The only king stands on the standard chess board. You are given his position in format “cd”, where c is the column from ‘a’ to ‘h’ and d is the row from ‘1’ to ‘8’. Find the number of moves permitted for the king.
这里写图片描述

King moves from the position e4

Input

The only line contains the king’s position in the format “cd”, where ‘c’ is the column from ‘a’ to ‘h’ and ‘d’ is the row from ‘1’ to ‘8’.
Output

Print the only integer x — the number of moves permitted for the king.

Example
Input

e4

Output

8

题解:简单模拟。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LiangJiaJun main
using namespace std;
char s[4];
int x,y;
bool genc(int a){
     return (a == 8 || a == 1);
}
int LiangJiaJun(){
    scanf("%s",s+1);
    x=s[1]-'a'+1;y=s[2]-'0';
    if(genc(x)&&genc(y)){
        puts("3");
        return 0;
    }
    if( (genc(x)&&!genc(y)) || (!genc(x)&&genc(y)) ){
        puts("5");return 0;
    }
    if(!genc(x)&&!genc(y)){
        puts("8");return 0;
    }
    return 0;
}

B. Optimal Point on a Line

You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line.

The second line contains n integers xi ( - 109 ≤ xi ≤ 109) — the coordinates of the given n points.
Output

Print the only integer x — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.

Example
Input

4
1 2 3 4

Output

2

题意:给N个数轴上的点,从中找到一个点,使得该点到其他所有点的距离之和最小。该点在数轴上的位置。(距离相同的话取数轴坐标靠左边的点)
题解:这很显然先排个序,然后最中间的一个或两个点就是答案了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define LiangJiaJun main
using namespace std;
int n,a[300004];
long long xp,xr;
int LiangJiaJun(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    if(n % 2 == 0){
        for(int i=1;i<=n;i++)xp += abs(a[i]-a[n/2]);
        for(int i=1;i<=n;i++)xr += abs(a[i]-a[n/2+1]);
        if(xr < xp) printf("%d\n",a[n/2+1]);
        else printf("%d\n",a[n/2]);
    }
    else {
        printf("%d\n",a[n/2+1]);
    }
    return 0;
}

C. Magic Odd Square

Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.
Input

The only line contains odd integer n (1 ≤ n ≤ 49).
Output

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.

Examples
Input

1

Output

1

Input

3

Output

2 1 4
3 5 7
6 9 8

题意:NOIP2015第一题。。。。。叫你填一个n*n大小的幻方,每个数字必须不重复,n是奇数。且所有数字必须在1到n^2之内。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define LiangJiaJun main
using namespace std;
int a[54][54],n;
int LiangJiaJun(){
    scanf("%d",&n);
    a[1][n/2+1] = 1;
    int nowx = 1, nowy = n/2+1 , k = 2;
    while(k<=n*n){
        bool t=0;
        int p=nowx-1,q=nowy+1;
        if(p>0&&q<=n){
            if(a[p][q]==0)a[p][q]=k;else t=1;
            if(!t){nowx=p;nowy=q;++k;continue;}
        }
        if(p<=0&&q<=n){
            p=n;
            if(a[p][q]==0)a[p][q]=k;else t=1;
            if(!t){nowx=p;nowy=q;++k;continue;}
        }
        if(p>0&&q>n){
            q=1;
            if(a[p][q]==0)a[p][q]=k;else t=1;
            if(!t){nowx=p;nowy=q;++k;continue;}
        }
        p=nowx+1;q=nowy;
        nowx=p;nowy=q;
        a[p][q]=k;
        k++;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}

D. Two Arithmetic Progressions

You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R and x = a1k’ + b1 = a2l’ + b2, for some integers k’, l’ ≥ 0.
Input

The only line contains six integers a1, b1, a2, b2, L, R (0 < a1, a2 ≤ 2·10^9,  - 2·10^9 ≤ b1, b2, L, R ≤ 2·10^9, L ≤ R).
Output

Print the desired number of integers x.

Examples
Input

2 0 3 3 5 21

Output

3

Input

2 4 3 0 6 17

Output

2

题意:求一共有多少个整数符合x( L<=x<=R ),使得a1 * k+b1 = a2 * l + b2 = x 的两个解k和l都为非负整数。
题解:这种题目说实话好恶心。说白了就是解方程嘛。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define LiangJiaJun main
using namespace std;
long long a1,b1,a2,b2,L,R;
long long gcd(long long x,long long y){return y==0?x:gcd(y,x%y);}
long long res1,res2,x,lcm,temp;
bool ok=0;
int LiangJiaJun(){
    scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&a1,&b1,&a2,&b2,&L,&R);
    if(a1<a2){
        swap(a1,a2);
        swap(b1,b2);
    }
    L=max(L,max(b1,b2));
    lcm=(a1*a2)/gcd(a1,a2);
    res1=(b1%a1+a1)%a1;
    res2=(b2%a2+a2)%a2;
    temp=x=L+(a1+res1-(L%a1))%a1;
    while(x<=temp+lcm && x<=R){
        if(((x%a2)+a2)%a2 == res2){
            ok=1; break;
        }
        else x+=a1;
    }
    if(ok)printf("%I64d\n",(R-x)/lcm+1);
    else printf("0\n");
    return 0;
}

E. Generate a String

zscoder wants to generate an input file for some programming competition problem.

His input is a string consisting of n letters ‘a’. He is too lazy to write a generator so he will manually generate the input in a text editor.

Initially, the text editor is empty. It takes him x seconds to insert or delete a letter ‘a’ from the text file and y seconds to copy the contents of the entire text file, and duplicate it.

zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters ‘a’. Help him to determine the amount of time needed to generate the input.
Input

The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters ‘a’ in the input file and the parameters from the problem statement.
Output

Print the only integer t — the minimum amount of time needed to generate the input file.

Examples
Input

8 1 1

Output

4

Input

8 1 10

Output

8

题意:可以花费x的代价使得一个数加一或者减一,或者y的代价使得他乘2,开始这个数是0,问达到n需要多少的代价
题解:有一个显然的结论,如果我要进行减一操作,那么我之前一定有一次乘二的操作。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define LiangJiaJun main
using namespace std;
long long f[20000004];
int n,x,y;
int LiangJiaJun(){
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<=n;i++)f[i]=min(f[i-1]+x,f[(i+1)/2]+y+x*(i%2==1));
    cout<<f[n]<<endl;
    return 0;
}


0
0
查看评论

Educational Codeforces Round 27

A 题意:把2 * n个人分成两组,使得无论两组的人怎么进行比赛 第一组的人始终都要保持全赢,如果两个人能力值相等两人都可以赢 思路:排序后只要保证n + 1个人的能力值大于第n个人的能力值即可 #include #include #include #include #include #i...
  • sasuke__
  • sasuke__
  • 2017-08-23 10:35
  • 198

Educational Codeforces Round 8 总结

A. Tennis Tournament time limit per test 1 second memory limit per test 256 megabytes input standard input output standard out...
  • zyx520ytt
  • zyx520ytt
  • 2016-02-21 02:47
  • 589

Educational Codeforces Round 36 题解

总结 第一次打cf的edu round,发现是acm赛制,感觉比平常的cf赛制要好玩一些。这场的题目比较水,当然我没打过其他场不能做比较。然而因为时间不太够所以并没有AK,果然自己跟Claris等神牛还是有很大差距的。下面附上我的成绩: 这才刚结束,还没有hack完,所以感觉应该还能再升几名...
  • qq_33229466
  • qq_33229466
  • 2018-01-14 00:40
  • 274

Educational Codeforces Round 17 C && codeforces 762C C. Two strings 详细的题解 (前后缀应用)

C. Two strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ...
  • qq_34374664
  • qq_34374664
  • 2017-02-02 13:39
  • 785

Codeforces Educational Codeforces Round 37 E

You are given an undirected graph consisting of n vertices and edges. Instead of giving you the edges that exist in the graph, we give you m unordere...
  • yqdjl6
  • yqdjl6
  • 2018-02-03 18:16
  • 48

Educational Codeforces Round 37 (Rated for Div. 2)【A B C】【水】【模拟】

嗖的一下! A #include using namespace std; #define ll long long int a[500]; int c[500]; int main() { int N; cin >> N; while(N--) { ...
  • Head_Hard
  • Head_Hard
  • 2018-02-03 16:18
  • 56

Educational Codeforces Round 36 (Rated for Div. 2) 题解

先总结一波 第一次打cf,感觉还不错,题目做得挺顺手。虽然开始30min才想起来有这么个比赛来着。。 纪念一下第一次的rank,话说题真是水 这是大概还剩下5min的时候截的,实际可能会掉一点吧 第二天更新: 原来d题真的会被卡,果然还是要tarjan找一个环来删边 hackin...
  • jpwang8
  • jpwang8
  • 2018-01-13 23:16
  • 241

Educational Codeforces Round 34 (A-E题解)

A:给你无限的3和7判断能不能凑成n 题解:相当于无限背包计数预处理一下判断能不能凑到即可 #include #include #include #include using namespace std; int dp[105]; int main(){ int t; dp[0]...
  • a1325136367
  • a1325136367
  • 2017-12-14 13:54
  • 70

Educational Codeforces Round 37

题面题目详见CodeForces 先大概的写个翻译。。。A有一个长度为nn的花园 有KK个水龙头, 假设水龙头的位置在xx 1s1s后xx会被灌溉 2s2s后[x−1,x+1][x-1,x+1]会被灌溉 jsjs后[x−j+1,x+j−1][x-j+1,x+j-1]会被灌溉 问这个花园...
  • qq_30974369
  • qq_30974369
  • 2018-02-03 17:19
  • 89

Educational Codeforces Round 37 B. Tea Queue

题意: 一群人按给定顺序排队喝茶,只能在某个时间段喝茶; 思路: 有点笨的涂色的方法,每个人能在哪一点能喝到茶,之前的都做标记; #include #include #include #include #include #include #include #include #incl...
  • xiang_6
  • xiang_6
  • 2018-02-04 23:33
  • 37
    个人资料
    • 访问:18662次
    • 积分:1377
    • 等级:
    • 排名:千里之外
    • 原创:125篇
    • 转载:1篇
    • 译文:0篇
    • 评论:4条
    最新评论