A - Grouping 2


Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

There are N students in a school.

We will divide these students into some groups, and in each group they will discuss some themes.

You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.

Divide the students so that the number of groups consisting of three or more students is maximized.

Constraints

  • 1≤N≤1000
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N

Output

If you can form at most x groups consisting of three or more students, print x.


Sample Input 1

Copy
8

Sample Output 1

Copy
2

For example, you can form a group of three students and another of five students.


Sample Input 2

Copy
2

Sample Output 2

Copy
0

Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.


Sample Input 3

Copy
9

Sample Output 3

Copy
3

题目大意:给定N个人,要求尽可能划分为3个或3个人以上的小组。求人数大于等于3的小组个数。

题解:贪心的考虑,把所有人划分为3个人的小组,最后一个小组人数可能不足3个人,如果存在不满足条件的一组,就划分到最后一组里,形成较大的一组。答案就是$\lfloor\frac N3\rfloor$.

#include <cstdio >
int N;
int main()
{
scanf("%d",&N);
printf("%d\n",N/3);
}

  

B - Hina Arare


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

In Japan, people make offerings called hina arare, colorful crackers, on March 3.

We have a bag that contains N hina arare. (From here, we call them arare.)

It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.

We have taken out the arare in the bag one by one, and the color of the i-th arare was Si, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.

If the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.

Constraints

  • 1≤N≤100
  • Si is PWG or Y.
  • There always exist ij and k such that Si=PSj=W and Sk=G.

Input

Input is given from Standard Input in the following format:

N
S1 S2 SN

Output

If the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.


Sample Input 1

Copy
6
G W Y P Y W

Sample Output 1

Copy
Four

The bag contained arare in four colors, so you should print Four.


Sample Input 2

Copy
9
G W W G P W P G G

Sample Output 2

Copy
Three

The bag contained arare in three colors, so you should print Three.


Sample Input 3

Copy
8
P Y W G Y W Y Y

Sample Output 3

Copy
Four

Submit

题目大意:给定一个颜色序列,统计序列中颜色种数。

题解:gg。

#include<cstdio>
#include<cctype>
#include<set>
using namespace std;
int n;
set<char> s;
char ch[2333];
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",ch);
s.insert(ch[0]);
}
if(s.size()==3)puts("Three");
else puts("Four");
return 0;
}

其实把题目读漏了,只需要颜色序列只有两种,选择一个特征颜色判断一下就行了。

#include<cstdio>
int N;
char c;
int main()
{
scanf("%d",&N);
bool flag=false;
for(int i=0; i<N; i++)
{
scanf("%c",&c);
if(c=='Y')flag=true;
}
if(flag)puts("Four");
else puts("Three");
return 0;
}

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

Copy
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

Copy
2

We can choose three people with the following names:

  • MASHIKERUMOIHABORO

  • MASHIKERUMOIHOROKANAI

Thus, we have two ways.


Sample Input 2

Copy
4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

Copy
0

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


Sample Input 3

Copy
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

Copy
7

Submit

题目大意:给定一堆字符串,从中选出以‘M’,‘A’,‘R’,‘C’或‘H’开头的字符串形成一个三个字符串组成的排列,求出排列种数。

题解:由于数据范围很小,可以暴力枚举10种排列的方案数,做个积就行了。

#include<iostream>
using namespace std;
long long n,sum1,sum2,sum3,sum4,sum5,ans;
char a[100006][200];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{
if(a[i][0]=='M')sum1++;
if(a[i][0]=='A')sum2++;
if(a[i][0]=='R')sum3++;
if(a[i][0]=='C')sum4++;
if(a[i][0]=='H')sum5++;
}
ans+=sum1*sum2*sum3;
ans+=sum1*sum2*sum4;
ans+=sum1*sum2*sum5;
ans+=sum1*sum3*sum4;
ans+=sum1*sum3*sum5;
ans+=sum1*sum4*sum5;
ans+=sum2*sum3*sum4;
ans+=sum2*sum3*sum5;
ans+=sum2*sum4*sum5;
ans+=sum3*sum4*sum5;
cout<<ans<<endl;
return 0;
}

  

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

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

Sample Output 1

Copy
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

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

Sample Output 2

Copy
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

Copy
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

Copy
0
5
0

题目大意:

给定一个300*300的矩阵,10^5组询问,每次询问跳到指定有指定数字的格子的代价。
跳跃方式:
开始,在有给定数字的格子上。
令x是格子上出现的数字,跳到写有x+d的格子上,如果没有到达给定的格子R,就继续跳跃,直到跳到给定的格子。
代价即两格子之间的曼哈顿距离。

题解:由于询问次数很大,所以直接暴力模拟肯定会TLE。如何处理?注意到D是固定的,预处理出一个dp数组,dp[i]表示跳到编号为i的格子需要的最小魔法点数。

很容易得出DP方程:dp[i]=dp[i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D])。

状态的转移是从这个格子的前一个格子转移而来。

#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]);
}
}

  

AtCoder Beginner Contest 089完整题解的更多相关文章

  1. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  2. AtCoder Grand Contest 021完整题解

    提示:如果公式挂了请多刷新几次,MathJex的公式渲染速度并不是那么理想. 总的来说,还是自己太弱了啊.只做了T1,还WA了两发.今天还有一场CodeForces,晚上0点qwq... 题解还是要好 ...

  3. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  4. Atcoder Beginner Contest 138 简要题解

    D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...

  5. AtCoder Beginner Contest 089 D - Practical Skill Test

    Problem Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th ...

  6. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  7. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  8. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  9. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

随机推荐

  1. Boost Asioserver使用

    今天主要想说道说道boost里面的网络通信库怎样设计和使用,由于近期一直在和网络一起工作,大数据处理和机器学习都离不开最后使用网络进行上线部署.先看看所有的源码吧. #include <cstd ...

  2. zoj 1610 Count the Colors 【区间覆盖 求染色段】

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  3. 一个APP爆炸的时代,假设没有wifi

    我们每天都离不开的微信,又传来了一个新消息.你造?微信公众平台新增了设备功能.眼下可支持可穿戴设备,将来呢,前景不可限量!能够想象,"后果"是我们越来越离不开微信,依附于它.这样的 ...

  4. 《Head First 设计模式》学习笔记——代理模式

    设计模式 代理模式:为还有一个对象提供一个替身或占位符以控制对这个对象的訪问. 使用代理模式创建代表对象,让代表对象控制某对象的訪问,被代理的对象能够使远程的对象(远程代理).创建开销大的对象(虚拟代 ...

  5. mysql 多日志表结果集合拼接存储过程

    通常单天的日志 仅仅记录当天的日志信息,假设须要查看一月内的日志信息须要对每天的日志表结果集合进行拼接,通经常使用到 union . 储存过程: drop PROCEDURE if EXISTS un ...

  6. EF TMD

    TMD 几个月前,本着学习的心态,首次在项目中应用EF.因为这里老是赶.赶.赶,当时只是匆匆而就,浅尝辄止,搞到现在对EF一知半解,每次在新项目使用,都担惊受怕,大费周折,不知道什么时候,在什么地方就 ...

  7. 8.30 "我什么都不会"

    /* 抢名额第一场 GG "我什么都不会阿" 这场磕死在E题了 按说应该能想到费马小定理 毕竟p is a prime 别的队都过了 大家都比较熟悉的就只有这一个 然后还有I题一开 ...

  8. 【Poj2960】S-Nim & 博弈论

    Position: http://poj.org/problem?id=2960 List Poj2960 S-Nim List Description Knowledge Solution Noti ...

  9. [POI 2007] Zap

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1101 [算法] 首先 , 问题可以转化为求GCD(x,y) = 1,x <= ...

  10. km算法(二分图最大权匹配)学习

    啦啦啦! KM算法是通过给每个顶点一个标号(叫做顶标)来把求最大权匹配的问题转 化为求完备匹配的问题的.设顶点Xi的顶标为A[i],顶点Yi的顶标为B[i],顶点Xi与Yj之间的边权为w[i,j].在 ...