G. Fake News (easy)
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...

Input

The first and only line of input contains a single nonempty string s of length at most 1000 composed of lowercase letters (a-z).

Output

Output YES if the string s contains heidi as a subsequence and NO otherwise.

Examples
input
abcheaibcdi
output
YES
input
hiedi
output
NO
Note

A string s contains another string p as a subsequence if it is possible to delete some characters from s and obtain p.

看下给你的字符串是否存在“heidi”

#include<stdio.h>
char s[]="heidi",st[];
int n,num=;
int main()
{
scanf("%s",st+);
for(int i=;st[i];++i)
{
if(st[i]==s[num])
++num;
if(num==) return *puts("YES");
}
puts("NO");
return ;
}
M. April Fools' Problem (easy)
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers nk and a sequence of npositive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal.

However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools!

Input

The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains nspace-separated integers a1, ..., an (1 ≤ ai ≤ 104).

Output

Output one number.

Examples
input
8 5
1 1 1 1 1 1 1 1
output
5
input
10 3
16 8 2 4 512 256 32 128 64 1
output
7
input
5 1
20 10 50 30 46
output
10
input
6 6
6 6 6 6 6 6
output
36
input
1 1
100
output
100
我在做这些水题真的好么?只当练英语了,n个数选k个最小的和,不开心的时候就A水题?
#include <bits/stdc++.h>
int a[];
using namespace std;
int main() {
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int s=;
for(int i=;i<k;i++)
s+=a[i];
printf("%d",s);
return ;
}
J. Send the Fool Further! (easy)
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on.

Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank?

Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends ab know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly.

Jenny is given the number 0.

Input

The first line of the input contains the number of friends n (3 ≤ n ≤ 100). The next n - 1 lines each contain three space-separated integers uv and c (0 ≤ u, v ≤ n - 1, 1 ≤ c ≤ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c.

It is guaranteed that the social network of the input forms a tree.

Output

Output a single integer – the maximum sum of costs.

Examples
input
4
0 1 4
0 2 2
2 3 3
output
5
input
6
1 2 3
0 2 100
1 4 2
0 3 7
3 5 10
output
105
input
11
1 0 1664
2 0 881
3 2 4670
4 2 1555
5 1 1870
6 2 1265
7 2 288
8 7 2266
9 2 1536
10 6 3378
output
5551
Note

In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).

就是简单的DFS一遍,找到从根到叶的最长路,这个自己当然是想不出来的,别人的代码真的很巧妙

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i)
const int N = ;
using namespace std ;
int n, ter[N], e, nxt[N], lnk[N], w[N] ;
void add(int x, int y, int z) {
ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e, w[e] = z ;
}
int dfs(int p, int las) {
int ret = ;
for (int i = lnk[p]; i; i = nxt[i]) if (ter[i] != las)
ret = max(ret, dfs(ter[i], p) + w[i]) ;
return ret ;
} int main() {
scanf("%d", &n) ;
int x, y, z ;
rep(i, , n - ) {
scanf("%d%d%d", &x, &y, &z) ;
++ x, ++ y ;
add(x, y, z) ;
add(y, x, z) ;
}
printf("%d\n", dfs(, )) ;
return ;
}
A. Heidi and Library (easy)
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.

We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 ≤ i ≤ n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.

Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.

There is a problem, though. The capacity of the library is k – this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.

You are given k and the sequence of requests for books a1, a2, ..., an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?

Input

The first line of input will contain two integers n and k (1 ≤ n, k ≤ 80). The second line will contain n integers a1, a2, ..., an(1 ≤ ai ≤ n) – the sequence of book requests.

Output

On a single line print the minimum cost of buying books at the store so as to satisfy all requests.

Examples
input
4 80
1 2 2 1
output
2
input
4 1
1 2 2 1
output
3
input
4 2
1 2 3 1
output
3
Note

In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.

In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.

In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day.

Q巨和我们讲这个是页面置换算法,其中最完美的是OPT,但是好像硬件并没有这样实现

最佳置换算法(OPT)

什么是OPT

最佳置换算法,其所选择的被淘汰的页面将是以后永不使用的,或是在最长(未来)时间内不再被访问的页面。采用最佳置换算法通常可保证最低的缺页率。但是人们目前还无法与之,一个进程在内存的若干个页面中,哪一个页面是未来最长时间内不再被访问的,因而该算法是无法实现的,但是可以利用该算法取评价其他的算法。

算法思想

举例如下:

 

我们将页面队列存在一个Vector动态数组中。我们可以从图中得知:当发生页面置换时,就要寻找在未来最长时间内不再被访问的页面,将其置换出去,比如当内存中存在的页面为 7、0、1,且要访问页面2时,此时我们要寻找页面队列中将要访问到的页面2以后的页面队列(0、3、0、4、2、3、0、3、2、1、2、0、1、7、0、1)中,页面7、0、1哪个最久未被访问到,即寻找页面7、0、1在以后的队列中第一次出现的这三个页面的下标值最大的那一个。因为页面7在后面的页面队列中再次被访问到是数组中下标为17的地方,页面0再次被访问到是数组下标为4的地方,页面1再次被访问的是数组中下标为13,所以页面7是未来最久才被访问的页面,所以将页面7置换出去,将页面2调入内存中。

它通常有两个参数,即需要刷新的页面和时间,然后通过贪心算法进行求解

上面的这道题可以理解为你只能有k本书,而且n天内每个人到来看他所要的书都要有书读,所以就成了保留哪本书的贪心问题,所以每次去掉元素,应该要做的是去掉下一次出现位置最晚的元素!这个元素占用图书馆空间的时间最长!存在a[i]就是这本书买了还没有删除,如果当前图书数等于k,你又要读现在的这本书,只能先进行删除操作,再进行插入。显而易见,每次插入就是又去买了一本书。

#include <bits/stdc++.h>
using namespace std;
int a[];
int n, k;
int main()
{
scanf("%d%d", &n, &k);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
set <int> s;
int t = ;
for (int i = ; i < n; i++)
{
if (!s.count(a[i]))
{
if (s.size() == k)
{
int M = -, p = -;
for (auto it = s.begin(); it != s.end(); it++)
{
int j;
for (j = i; j < n; j++)
{
if (a[j] == *it)
{
break;
}
}
if (j > M)
{
M = j;
p = *it;
}
}
s.erase(p);
}
s.insert(a[i]);
t++;
}
}
printf("%d\n", t);
}

Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)的更多相关文章

  1. Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) J

    Description Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their comm ...

  2. Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) M

    Description The marmots have prepared a very easy problem for this year's HC2 – this one. It involve ...

  3. Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) A

    Description Your search for Heidi is over – you finally found her at a library, dressed up as a huma ...

  4. Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)

    http://codeforces.com/contest/1184 A1 找一对整数,使x^x+2xy+x+1=r 变换成一个分式,保证整除 #include<iostream> #in ...

  5. Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)F3 - Lightsabers (hard)

    题意:n个数字1-m,问取k个组成的set方案数 题解:假设某个数出现k次,那么生成函数为\(1+x+...+x^k\),那么假设第i个数出现ai次,结果就是\(\sum_{i=1}^m(1+x+.. ...

  6. CF 690C3. Brain Network (hard) from Helvetic Coding Contest 2016 online mirror (teams, unrated)

    题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一 ...

  7. [Helvetic Coding Contest 2017 online mirror]

    来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包 ...

  8. 【Codeforces】Helvetic Coding Contest 2017 online mirror比赛记

    第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: l ...

  9. Helvetic Coding Contest 2016 online mirror A1

    Description Tonight is brain dinner night and all zombies will gather together to scarf down some de ...

随机推荐

  1. Permutations(copy)

    Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the follo ...

  2. Objective-C language

    Objective-C is the primary language used to write Mac software. If you're comfortable with basic obj ...

  3. 判断后台service是否在运行

    public static boolean isServiceRunning(Context mContext,String className) { boolean isRunning = fals ...

  4. Oracle Flashback Technology【闪回技术】

    -------------------------与其他数据库相比,Oracle的闪回让开发者多了一条选择的路. Flashback的目的 先看下Oracle官方文档中的解释: Oracle Flas ...

  5. HDU 4276 The Ghost Blows Light (树形DP,变形)

    题意:给定一棵n个节点的树,起点是1,终点是n,每经过一条边需要消耗Ti天,每个点上有一定量的珠宝,要求必须在t天内到达终点才可以将珠宝带出去,问至多能带多少珠宝? 思路: 注意Ti可以为0,而且有可 ...

  6. 关于java中实现在oracle数据库中实现对中文首字母进行排序的解决方案

    首先介绍Oracle 9i新增加的一个系统自带的排序函数 1.按首字母排序 在oracle9i中新增了按照拼音.部首.笔画排序功能.设置NLS_SORT值     SCHINESE_RADICAL_M ...

  7. Kubernetes介绍与特性

    1.Kubernetes 是什么 简单的来说,k8s可以理解为,一个容器平台,一个微服务平台,便携式云平台,我们那可以很快速的搭建一个服务,快速的运行起来 2.Kubernetes特性

  8. caffe layer层cpp、cu调试经验和相互关系

    对于layer层的cpp文件,你可以用LOG和printf.cout进行调试,cu文件不能使用LOG,可以使用cout,printf. 对于softmaxloss的layer层,既有cpp文件又有cu ...

  9. 第2节 azkaban调度:16、azkaban的介绍以及azkaban的soloserver的安装使用

    2. 工作流调度器azkaban 2.1 概述 azkaban官网: https://azkaban.github.io/ 2.1.1为什么需要工作流调度系统 l  一个完整的数据分析系统通常都是由大 ...

  10. javase(13)_网络编程

    一.概述 1.网络编程的核心是IP.端口(表示应用程序).协议三大元素 2.网络编程的本质是进程间通信 3.网络编程的2个主要问题:1是定位主机,2是数据传输 二.网络通信的概念 1.网络通信协议 计 ...