2018.03.04 晚上Atcoder比赛
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
M,A,R,CorH. - 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
- Si≠Sj(i≠j)
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:
MASHIKE,RUMOI,HABOROMASHIKE,RUMOI,HOROKANAI
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 |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≤D≤H×W
- 1≤Ai,j≤H×W
- Ai,j≠Ax,y((i,j)≠(x,y))
- 1≤Q≤105
- 1≤Li≤Ri≤H×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;
],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比赛的更多相关文章
- 20172319 2018.03.27-04.05 《Java程序设计》第4周学习总结
20172319 2018.03.27-04.05 <Java程序设计>第4周学习总结 教材学习内容总结 第四章 编写类 类与对象的回顾:对象是有状态的,状态由对象的属性值确定.属性由类中 ...
- 新手C#string类常用函数的学习2018.08.04
ToLower()用于将字符串变为小写,注意字符串的不可变特性,需要重新赋值给另一个字符串变量. s = s.ToLower();//字符串具有不可变性,转换后需要重新赋值,不可仅有s.ToLower ...
- 新手C#int.Parse、int.TryParse的学习2018.08.04
int.Parse()用于将字符串转换为32为int类型,但是在遇到非数字或者类似1.545这种小数的时候会报错,后来采用了int.TryParse,这个在转换后会判断是否可以正常转换,若不能,会返回 ...
- 新手C#参数类型ref、out、params的学习2018.08.04
ref用于传递参数时,将实参传递到函数中,是引用参数,在使用前必须被赋值.string类型也同样适用. static void Main(string[] args) { string a1,a2; ...
- 新手C#重载、重写的学习2018.08.04
重载:在同一类(class)中,使用相同的方法名称,不同的参数和(不一定)不同的返回值类型构造成的方法. 举例: class OverLoadTest { public void Hello() { ...
- 【VSCode】Windows下VSCode编译调试c/c++【更新 2018.03.27】
--------– 2018.03.27 更新--------- 便携版已更新,点此获取便携版 已知BUG:中文目录无法正常调试 用于cpptools 0.15.0插件的配置文件更新 新的launch ...
- 2018/03/27 每日一个Linux命令 之 cron
Cron 用于配置定时任务. -- 环境为 Ubuntu16-04 -- 先说说怎么配置一个简单的定时任务.直观的可以看到效果. 之前在网上查找资料,对Shell编程不熟悉的实在是很头疼,走了不少弯路 ...
- 2018/03/31 每日一个Linux命令 之 date
date 命令主要用于查看和修改时间和时区 -- 这里主要学习基本的查看和设置时间和时区的方法. 直接显示日期 date '+%D' 效果 vagrant@hong:~$ date '+%D' 03/ ...
- EZ 2018 03 23 NOIP2018 模拟赛(五)
链接:http://211.140.156.254:2333/contest/65 这次Rating重回Rank18,我是20的守门员(滑稽) 这次题目和数据普遍偏水,我T2打错了一个变量名竟然过了所 ...
随机推荐
- C# 生成pdf文件客户端下载
itextsharp.dll 下载:http://sourceforge.net/projects/itextsharp/ 程序需引用:itextsharp.dll,itextsharp.pdfa.d ...
- 我所不知道的 javascript 函数
对字符串进行 Base64 加密: window.btoa(str) ---转码 window.atob(str) ---解码 这种加密方法不能加密中文,可以先进行 encodeURIComponen ...
- 批量将网页转换成图片或PDF文档技巧分享
工作中我们有时要将一些批量的网页转换成图片或者PDF文档格式,尽管多数浏览器具有滚动截屏或者打印输出PDF文档功能.可是假设有几十上百张网页须要处理,那也是要人命的.所以我一直想找一款可以批量处理该工 ...
- js20170320
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- bzoj2780
AC自动机+树链剖分+线段树/树状数组+dfs序+树链的并 题意:给出n个母串和q个询问串,对于每个询问串输出有多少个母串包含这个询问串 N=∑|母串|<=10^5 Q=∑|询问串|<=3 ...
- PCB OD工具破解实例应用
以下破解Genesis为例,对OD工具使用进行实例讲解 工具简单 介绍下下载地址: OD工具:是一个新的动态追踪工具,将IDA与SoftICE结合起来的思想,Ring 3级调试器, 是为当今最为流行的 ...
- 路一直都在——That's just life
分享一首很喜欢的歌,有时候歌词写得就是经历,就是人生... 穿过人潮汹涌灯火栏栅 没有想过回头 一段又一段走不完的旅程 什么时候能走完 我的梦代表什么 又是什么让我们不安 That's just li ...
- knockjs
用VS2012建立Web站点有个新惊喜,默认加了KnockoutJS这个Javascript的MVVM模式的实现库,方便Web前端的开发 官方站点 √主页: http://www.knockoutj ...
- 【BZOJ4566_洛谷3181】[HAOI2016]找相同字符(SAM)
自己yy的方法yyyyyyyy着就A了,写篇博客庆祝一下. 题目: 洛谷3181 分析: SAM(可能是)模板题(不会SAM的同学戳我:[知识总结]后缀自动机的构建). 对\(s1\)建出SAM,用\ ...
- ACM_小Z的A+B
小Z的A+B Time Limit: 2000/1000ms (Java/Others) Problem Description: 小Z最喜欢A+B了,没事就研究研究,比如什么大整数A+B(就是100 ...