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[];
]={,,,,,,,,,};
]={,,,,,,,,,};
]={,,,,,,,,,};
int main()
{
scanf("%d",&N);
;i<N;i++)
{
cin>>s;
]==’M’)m++;
]==’A’)a++;
]==’R’)r++;
]==’C’)c++;
]==’H’)h++;
}
D[]=m,D[]=a,D[]=r,D[]=c,D[]=h;
ll res=;
;d<;d++)
res+=D[P[d]]*D[Q[d]]*D[R[d]];
printf("%lld\n",res);
}

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

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>

using namespace std;
],ans;
];
int main()
{
    scanf("%lld",&n);
    ;i<=n;i++) cin>>s[i];
    ;i<=n;i++){
        ]==];
        ]==];
        ]==];
        ]==];
        ]==];
    }
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    ans+=a[]*a[]*a[];
    printf("%lld\n",ans);
    ;
}

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 |xi|+|yj| 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 RiLi 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
  • (RiLi) 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;
],py[];
];
int main()
{
scanf("%d%d%d",&H,&W,&D);
;i<H;i++)
{
;j<W;j++)
{
scanf("%d",&A);
px[A]=i,py[A]=j;
}
}
;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]);
}
}

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

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

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

2018.03.04 晚上Atcoder比赛的更多相关文章

  1. 20172319 2018.03.27-04.05 《Java程序设计》第4周学习总结

    20172319 2018.03.27-04.05 <Java程序设计>第4周学习总结 教材学习内容总结 第四章 编写类 类与对象的回顾:对象是有状态的,状态由对象的属性值确定.属性由类中 ...

  2. 新手C#string类常用函数的学习2018.08.04

    ToLower()用于将字符串变为小写,注意字符串的不可变特性,需要重新赋值给另一个字符串变量. s = s.ToLower();//字符串具有不可变性,转换后需要重新赋值,不可仅有s.ToLower ...

  3. 新手C#int.Parse、int.TryParse的学习2018.08.04

    int.Parse()用于将字符串转换为32为int类型,但是在遇到非数字或者类似1.545这种小数的时候会报错,后来采用了int.TryParse,这个在转换后会判断是否可以正常转换,若不能,会返回 ...

  4. 新手C#参数类型ref、out、params的学习2018.08.04

    ref用于传递参数时,将实参传递到函数中,是引用参数,在使用前必须被赋值.string类型也同样适用. static void Main(string[] args) { string a1,a2; ...

  5. 新手C#重载、重写的学习2018.08.04

    重载:在同一类(class)中,使用相同的方法名称,不同的参数和(不一定)不同的返回值类型构造成的方法. 举例: class OverLoadTest { public void Hello() { ...

  6. 【VSCode】Windows下VSCode编译调试c/c++【更新 2018.03.27】

    --------– 2018.03.27 更新--------- 便携版已更新,点此获取便携版 已知BUG:中文目录无法正常调试 用于cpptools 0.15.0插件的配置文件更新 新的launch ...

  7. 2018/03/27 每日一个Linux命令 之 cron

    Cron 用于配置定时任务. -- 环境为 Ubuntu16-04 -- 先说说怎么配置一个简单的定时任务.直观的可以看到效果. 之前在网上查找资料,对Shell编程不熟悉的实在是很头疼,走了不少弯路 ...

  8. 2018/03/31 每日一个Linux命令 之 date

    date 命令主要用于查看和修改时间和时区 -- 这里主要学习基本的查看和设置时间和时区的方法. 直接显示日期 date '+%D' 效果 vagrant@hong:~$ date '+%D' 03/ ...

  9. EZ 2018 03 23 NOIP2018 模拟赛(五)

    链接:http://211.140.156.254:2333/contest/65 这次Rating重回Rank18,我是20的守门员(滑稽) 这次题目和数据普遍偏水,我T2打错了一个变量名竟然过了所 ...

随机推荐

  1. 我的Go语言学习之旅七:创建一个GUI窗口

    在上次中,刚刚学过了  弹窗效果.这里再接着学习一下怎样创建一个窗口. 还是老路子,先上代码: package main import ( "github.com/lxn/go-winapi ...

  2. 如何用分布式缓存服务实现Redis内存优化

    Redis是一种支持Key-Value等多种数据结构的存储系统,其数据特性是“ALL IN MEMORY”,因此优化内存十分重要.在对Redis进行内存优化时,先要掌握Redis内存存储的特性比如字符 ...

  3. const与static类成员

    const成员函数作用1. 不能修改类的成员变量,同时不能调用类的非const成员函数.(const成员函数中,this的类型是一个指向const类类型对象的const指针,const成员函数返回*t ...

  4. 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 数据库连接不释放测试 连接池 释放连接 关闭连接 有关 redis-py 连接池会导致服务器产生大量 CLOSE_WAIT 的再讨论以及一个解决方案

    import pymysqlfrom redis import Redisimport time h, pt, u, p, db = '192.168.2.210', 3306, 'root', 'n ...

  5. js对象和json的区别

    他们两个没有什么关联只不过可以相互转换而已,就像json可以转化为java对象一样 注意:json只有字符串形式(就是我们常说的json字符串:key/value值和数组形式的字符串),没有什么jso ...

  6. Silverlight 2学习笔记一:初识Silverlight

    Silverlight,问世至今已有好一段时日了,向来只是只闻其名,不知其实,今天终于对Silverlight有了点初步的了解. 一.Silverlight是什么?Sliverlight是基于.NET ...

  7. jeesite ckfinder mac/linux 文件上传路径设置

    背景: 如果你使用的是Mac 或者 Ubuntu 这种 Unix系统的话,你一定知道Unix系统的文件路径分隔符是 / 而Windows系统文件分隔符是 \ 当你设置了jeesite.properti ...

  8. 安科 OJ 1054 排队买票 (递归,排列组合)

    时间限制:1 s 空间限制:128 M 题目描述 有M个小孩到公园玩,门票是1元.其中N个小孩带的钱为1元,K个小孩带的钱为2元.售票员没有零钱,问这些小孩共有多少种排队方法,使得售票员总能找得开零钱 ...

  9. AcWing算法基础1.1

    排序 快速排序(快排) 写题的时候用的不多基本都是直接sort ( ),面试可能要手撸快排,上模板 void quick_sort(int q[], int l, int r) { if(l > ...

  10. Elasticsearch索引的操作,利用kibana(如何创建/删除一个es的索引?)

    我们已经通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射.现在我们需要对这个建立索引的过程做更多的控制:我们想要确保这个索引有数量适中的主分 ...