码迷,mamicode.com
首页 > 其他好文 > 详细

2018.03.04 晚上Atcoder比赛

时间:2018-03-04 23:00:15      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:win   gpo   stream   following   through   log   lan   post   grid   

C - March


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

There are N people. The name of the i-th person is Si.

We would like to choose three people so that the following conditions are met:

  • The name of every chosen person begins with MARC or H.
  • There are no multiple people whose names begin with the same letter.

How many such ways are there to choose three people, disregarding order?

Note that the answer may not fit into a 32-bit integer type.

Constraints

  • 1≤N≤105
  • Si consists of uppercase English letters.
  • 1≤|Si|≤10
  • SiSj(ij)

Input

Input is given from Standard Input in the following format:

N
S1
:
SN

Output

If there are x ways to choose three people so that the given conditions are met, print x.


Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

  • MASHIKERUMOIHABORO

  • MASHIKERUMOIHOROKANAI

Thus, we have two ways.


Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

Note that there may be no ways to choose three people so that the given conditions are met.


Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7

 std:

技术分享图片
#include <cstdio >
#include <iostream >
using namespace std;
typedef long long ll;
string s;
int N;
ll m,a,r,c,h;
ll D[5];
int P[10]={0,0,0,0,0,0,1,1,1,2};
int Q[10]={1,1,1,2,2,3,2,2,3,3};
int R[10]={2,3,4,3,4,4,3,4,4,4};
int main()
{
scanf("%d",&N);
for(int i=0;i<N;i++)
{
cin>>s;
if(s[0]==’M’)m++;
if(s[0]==’A’)a++;
if(s[0]==’R’)r++;
if(s[0]==’C’)c++;
if(s[0]==’H’)h++;
}
D[0]=m,D[1]=a,D[2]=r,D[3]=c,D[4]=h;
ll res=0;
for(int d=0;d<10;d++)
res+=D[P[d]]*D[Q[d]]*D[R[d]];
printf("%lld\n",res);
}
View Code

暴力枚举每一种情况:共10种

技术分享图片
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>

using namespace std;
long long n,a[6],ans;
string s[200000];
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) cin>>s[i];
    for(int i=1;i<=n;i++){
        if(s[i][0]==M) ++a[1];
        if(s[i][0]==A) ++a[2];
        if(s[i][0]==R) ++a[3];
        if(s[i][0]==C) ++a[4];
        if(s[i][0]==H) ++a[5];
    }
    ans+=a[1]*a[2]*a[3];
    ans+=a[1]*a[2]*a[4];
    ans+=a[1]*a[2]*a[5];
    ans+=a[1]*a[3]*a[4];
    ans+=a[1]*a[3]*a[5];
    ans+=a[1]*a[4]*a[5];
    ans+=a[2]*a[3]*a[4];
    ans+=a[2]*a[3]*a[5];
    ans+=a[3]*a[4]*a[5];
    ans+=a[2]*a[4]*a[5];
    printf("%lld\n",ans);
    return 0;
}
View Code

 

 

D - Practical Skill Test


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).

The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is Ai,j.

You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x?i|+|y?j| magic points.

You now have to take Q practical tests of your ability as a magical girl.

The i-th test will be conducted as follows:

  • Initially, a piece is placed on the square where the integer Li is written.

  • Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not Ri. The test ends when x=Ri.

  • Here, it is guaranteed that Ri?Li is a multiple of D.

For each test, find the sum of magic points consumed during that test.

Constraints

  • 1≤H,W≤300
  • 1≤DH×W
  • 1≤Ai,jH×W
  • Ai,jAx,y((i,j)≠(x,y))
  • 1≤Q≤105
  • 1≤LiRiH×W
  • (Ri?Li) is a multiple of D.

Input

Input is given from Standard Input in the following format:

H W D
A1,1 A1,2  A1,W
:
AH,1 AH,2  AH,W
Q
L1 R1
:
LQ RQ

Output

For each test, print the sum of magic points consumed during that test.

Output should be in the order the tests are conducted.


Sample Input 1

3 3 2
1 4 3
2 5 7
8 9 6
1
4 8

Sample Output 1

5
  • 4 is written in Square (1,2).

  • 6 is written in Square (3,3).

  • 8 is written in Square (3,1).

Thus, the sum of magic points consumed during the first test is (|3?1|+|3?2|)+(|3?3|+|1?3|)=5.


Sample Input 2

4 2 3
3 7
1 4
5 2
6 8
2
2 2
2 2

Sample Output 2

0
0

Note that there may be a test where the piece is not moved at all, and there may be multiple identical tests.


Sample Input 3

5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
13 13
2 10
13 13

Sample Output 3

0
5
0

 std:DP预处理

技术分享图片
#include <cstdio >
#define abs(x) ((x>0)?x:(-(x)))
int H,W,D,A;
int Q,L,R;
int px[90001],py[90001];
int d[90001];
int main()
{
scanf("%d%d%d",&H,&W,&D);
for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++)
{
scanf("%d",&A);
px[A]=i,py[A]=j;
}
}
for(int i=D+1;i<=H*W;i++)
d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
scanf("%d",&Q);
while(Q--)
{
scanf("%d%d",&L,&R);
printf("%d\n",d[R]-d[L]);
}
}
View Code

 

说明一下:A B C D 共四题

由于A B 太水,且没有可取之处,所以不在博客显示

网址:https://abc089.contest.atcoder.jp/

2018.03.04 晚上Atcoder比赛

标签:win   gpo   stream   following   through   log   lan   post   grid   

原文地址:https://www.cnblogs.com/song-/p/8506435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!