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. CF1072B Curiosity Has No Limits

    思路: 对于序列t,只要第一个数确定了,后续的数也随之确定了.枚举四种情况即可.实现: #include <iostream> #include <vector> using ...

  2. PaaS优点与限制(3)

    PaaS优点与限制(3) PaaS学习笔记目录 PaaS基础学习(1) 在PaaS上开发Web.移动应用(2) PaaS优点与限制(3) 13. PaaS的核心服务 核心服务是指提供数据存储.SQl. ...

  3. 如何设置文件审计软件FileAudit的浏览选项

    FileAudit允许用户从审计访问事件中排除掉某些特定事件,用户可以把对于自身来说不敏感的文件审计访问事件设定在这些派出范围之类,这样一来就FileAudit就会自动过滤掉这些不明感时间,以便节约用 ...

  4. iOS组件化开发· 什么是组件化

    越来越多公司,开始了组件化,你还要等到什么时候...... 说到开发模式,我们最熟知的开发模式 MVC 或者最近比较热门的MVVM.但是我今天说的组件化的开发,其实MVC不是一类的.它其实是····· ...

  5. jdbc接口的一种类比——打酱油

    jdbc很简单,这里只是为了方便自己的记忆.模型也许有缺陷,但本质是相同的. jdbc可以屏蔽数据库的底层的不同,让我们有能力用java语言统一访问不同的数据库.就像打酱油一样,可以去超市买,也可以去 ...

  6. C++拾遗(一)——变量和基本类型

    今天看到一个小小的算法,交换两个数却不引入中间变量,想了下没什么思路.看了答案是这样: int a, b; a = a + b; b = a - b; a = a - b; 感觉还是挺有想法的,借此也 ...

  7. 洛谷 1164 小A点菜

    题目背景 uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种. uim指着墙上的价目表(太低级了没有菜单),说:“随便点”. 题目描述 不过uim由于买了一些辅(e ...

  8. 基于Vmware player的Windows 10 IoT core + RaspberryPi2安装部署

    本文记录了基于Vmware Player安装Windows10和VS2015开发平台的过程,以及如何在RaspberryPi2.0上启动Windows10 IoT core系统,并通过一个简单的hel ...

  9. 在Ubuntu16.04安装YouCompleteMe

    作为从事了4年多嵌入式Linux工作的软件工程师,最近决定完全在ubuntu上工作,使用vim进行代码的阅读和编辑,然后尝试去安装vim相关的各种插件.从来没用过代码补全的我,在网上找到了插件omni ...

  10. 用Hexo免费搭建你自己的博客

    Hexo基于node.js,可用于生成静态博客,结合github和Mac,可以专注创作了. 深入学习见文末引用. hexo安装 brew install node npm install hexo-c ...