Problem Description N frogs . Two frogs are friends if they come from the same country. The closest friends are a pair of friends with the minimum distance. Help us find that distance. Input First line contains an integer T, which indicates the numbe…
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5578 Description N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance betwee…
题意:给定一行字符串(都是小写字母),每一个字符都代表一只青蛙以及其国籍,若字符串中出现两个字符相同,则这两个字符所代表的青蛙来自同一国度,可称之为好朋友. 现在需要找到距离最近的好朋友并输出他们的距离. 思路:建立一个map映射表,映射关系为:字符<->字符所在字符串的位置,从字符串头部到尾部依次进行扫描,每扫到一个字符,可以找一找map表中有没有出现该字符,若没出现过则在 表中建立这个字符的关系,若map表中有该字符的记录,那么说明当前字符串代表的青蛙找到了一个朋友,可以计算他与朋友的距离…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5578 Friendship of Frog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 556    Accepted Submission(s): 355 Problem Description N frogs from differe…
Friendship of Frog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 135    Accepted Submission(s): 106 Problem Description N frogs from different countries are standing in a line. Each country i…
题 题意 求相同字母最近距离 分析 用数组保存各个字母最后出现的位置,维护最小距离. 代码 #include <cstdio> int c[30],n,p,a,minl; char ch; int main(){ scanf("%d ",&n); for(int i=1;i<=n;i++){ for(int j=0;j<27;j++)c[j]=0; p=1;minl=2000; while((ch=getchar())!='\n'){ a=ch-'a';…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并且使得机器的运行时间的和最小. 解法:按开始工作的时间从小到大排序后,用一个set容器维护一下,每次加入找set里面结束时间小于等于开始时间并且最近的点插入即可,然后如果没有小于开始时间的就重新开一台机器即可,这里可能有重复元素,需要multiset. #include <bits/stdc++.h…
http://acm.hdu.edu.cn/showproblem.php?pid=4302 题意: 在一条直线上,会有多条命令,如果是0,那么就会在x位置处出现一个蛋糕,如果是1,某人就会找到最近的蛋糕去吃.一开始在0坐标处,如果两边都有距离相同的蛋糕,则不改变方向.求经过的总距离. 思路: multiset维护,每次1命令时在multiset找距离最近的即可. #include<iostream> #include<cstdio> #include<set> usi…
题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b    a == 0 代表对 x == b轴处理: a == 1 代表 对y == b轴处理.处理即为把该轴上的点全部清空,输出清空的点的数量.已经清空的点,不计算在接下来的询问中. 思路:map + multiset 对于x轴和y轴,分别用两个map 映射,每一个x(或者y)轴都对应着一排点,这些点用multis…
Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2901    Accepted Submission(s): 941 Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this…