Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
1 second
256 megabytes
standard input
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...
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 YES if the string s contains heidi as a subsequence and NO otherwise.
abcheaibcdi
YES
hiedi
NO
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 ;
}
2 seconds
256 megabytes
standard input
standard output
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k 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!
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 one number.
8 5
1 1 1 1 1 1 1 1
5
10 3
16 8 2 4 512 256 32 128 64 1
7
5 1
20 10 50 30 46
10
6 6
6 6 6 6 6 6
36
1 1
100
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 ;
}
1 second
256 megabytes
standard input
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 a, b 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.
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 u, v 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 a single integer – the maximum sum of costs.
4
0 1 4
0 2 2
2 3 3
5
6
1 2 3
0 2 100
1 4 2
0 3 7
3 5 10
105
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
5551
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 ;
}
2 seconds
256 megabytes
standard input
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?
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.
On a single line print the minimum cost of buying books at the store so as to satisfy all requests.
4 80
1 2 2 1
2
4 1
1 2 2 1
3
4 2
1 2 3 1
3
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)
http://codeforces.com/contest/1184 A1 找一对整数,使x^x+2xy+x+1=r 变换成一个分式,保证整除 #include<iostream> #in ...
- 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+.. ...
- CF 690C3. Brain Network (hard) from Helvetic Coding Contest 2016 online mirror (teams, unrated)
题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一 ...
- [Helvetic Coding Contest 2017 online mirror]
来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包 ...
- 【Codeforces】Helvetic Coding Contest 2017 online mirror比赛记
第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: l ...
- Helvetic Coding Contest 2016 online mirror A1
Description Tonight is brain dinner night and all zombies will gather together to scarf down some de ...
随机推荐
- 前端之css(宽高)设置小技巧
一.css宽高自适应: 1.宽度自适应: 元素宽度设为100%(块状元素的默认宽度为100%) 注:应用在通栏效果中 2.高度自适应: height:auto;或者不设置高度 3.最小,最大高度,最小 ...
- Oracle查询排序asc/desc 多列 order by
查询结果的排序 显示EMP表中不同的部门编号. 如果要在查询的同时排序显示结果,可以使用如下的语句: SELECT 字段列表 FROM 表名 WHERE 条件 ORDER BY 字段名1 [ASC|D ...
- 安装ubuntu虚拟环境
一. 安装 1. 准备: 1). Oracle VM VirtualBox https://www.virtualbox.org/ 2). Ubuntu 18.04.2 LTS https://ubu ...
- 7.html超链接的使用
<html> <head> <title>第七课网页标签</title> <meta charset="utf-8"> ...
- 日常博客-png,jpeg,gif图片
个人博客记录:2017-11-09 png-----32位无损压缩算法形成的图片,主要用于logo小图标和一些点缀的小图像.放大缩小不会失真,质量好 jpeg,jpg-----压缩比例较高(可达到10 ...
- Clown without borders 2017/1/10
原文 You'll laugh, you'll cry It's aesy to imaginehow the activities of CWB produce many emotional and ...
- php日期时间和时间戳转化
echo date("Y-m-d H:i:s", 1409138643);echo strtotime('2014-08-28 23:00:00');
- WPF知识点全攻略02- WPF体系结构
WPF体系结构图: PersentationFramework.dll包含WPF顶层的类型,包括哪些表示窗口.面板以及其他类型控件的类型.他还实现了高层编程抽象,如样式.开发人员直接使用的大部分类都来 ...
- Python字符编码及字符串
字符编码 字符串是一种数据类型,但是字符串比较特殊的是编码问题,计算机只能处理数字,处理文本就需要将文本转换成数字. 计算机设计时8bit作为一个字节byte,一个字节能表示的最大整数就是(2^8)- ...
- CPP-基础:内部函数应该在当前源文件中说明和定义
static函数与普通函数作用域不同,仅在本文件.只在当前源文件中使用的函数应该说明为内部函数(static),内部函数应该在当前源文件中说明和定义.对于可在当前源文件以外使用的函数,应该在一个头文件 ...