Educational Codeforces Round 16

原创 2016年08月28日 14:16:00

抽空做了一下这些题。。。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;
}


版权声明:辛辛苦苦码字,你们转载的时候记得告诉我

相关文章推荐

Educational Codeforces Round 16 A. King Moves【模拟】

原题链接:http://codeforces.com/contest/710/problem/A 题意:在国际象棋上,给你将的位置,问你它可以走多少个方向。 AC代码:

Educational Codeforces Round 16 (A-E)

A. King Moves time limit per test 1 second memory limit per test 256 megabytes input standard ...

Educational Codeforces Round 16

果然还是很弱啊,写前几个水题的题解算了…… Educational Codeforces Round 16 A ————————————————————————————— 题意:给你国王的坐标...

Educational Codeforces Round 16 C. Magic Odd Square (构造)

链接C. Magic Odd Square题意构造一个n*n的矩阵,n为奇数,矩阵中的每个数都是1到n^2中的一个且不能重复,使得这个矩阵的每一行,每一列还有主对角线中数的和均为奇数。思路首先想到的是...

Educational Codeforces Round 16 -- E. Generate a String (DP)

大体题意: 一开始你有一个空的字符串,你要得到n 个‘a’字符,  你插入或者删除一个‘a’需要x秒,复制目前的字符串需要y秒,求最少多少秒! 思路: 赛后补得,没有时间做了= =! dp思想...

Codeforces 710 C. Magic Odd Square(构造)——Educational Codeforces Round 16

传送门Find an n × nn × n matrix with different numbers from 11 to n2n^2, so the sum in each row, colum...

Codeforces Educational Codeforces Round 16 部分题解

ECR场的题一般都比较水,而我这种菜鸡就只能写写这样的题解来安慰一下自己了。 A、B、C都是语言入门题,就不说了。贴上C找规律的代码:#include #include #include #incl...

【解题报告】Educational Codeforces Round 12

简略的解题报告。

Educational Codeforces Round 14

C. Exponential notation time limit per test 2 seconds memory limit per test 256 megabyte...

Educational Codeforces Round 9 -- B - Alice, Bob, Two Teams

B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes i...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)