codeforces58

来源:互联网 发布:广告宣传单设计软件 编辑:程序博客网 时间:2024/06/06 02:13

A. Chat room
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.

Input

The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.

Output

If Vasya managed to say hello, print "YES", otherwise print "NO".

Examples
input
ahhellllloou
output
YES
input
hlelo
output
NO


#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<list>#include<queue>#include<vector>using namespace std;const int maxn=10010;char str[maxn];int num[maxn];int main(){int n,i,j,k;scanf("%s",str);bool sign1=false,sign2=false,sign3=false,sign4=false,sign5=false;for(i=0;str[i];++i){if(str[i]=='h'){sign1=true;break;}}for(j=i;str[j];++j){if(str[j]=='e'){sign2=true;break;}}for(i=j;str[i];++i){if(str[i]=='l'){sign3=true;break;}}for(j=i+1;str[j];++j){if(str[j]=='l'){sign4=true;break;}}for(i=j;str[i];++i){if(str[i]=='o'){sign5=true;break;}}if(sign1&&sign2&&sign3&&sign4&&sign5){printf("YES\n");}else {printf("NO\n");}return 0;}

B. Coins
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.

Input

The first and only line contains an integer n (1 ≤ n ≤ 106) which represents the denomination of the most expensive coin.

Output

Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination n of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.

Examples
input
10
output
10 5 1
input
4
output
4 2 1
input
3
output
3 1

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<list>#include<queue>#include<vector>using namespace std;const int maxn=10010;int num[maxn];int main(){int n,cnt=0,i;scanf("%d",&n);while(n>1){printf("%d ",n);for(i=2;i*i<=n;++i){if(n%i==0)break;}if(n%i==0)n/=i;else n=1;}printf("1\n");return 0;}

C. Trees
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the n-th one) should be equal to each other, the heights of the 2-nd and the (n - 1)-th tree must also be equal to each other, at that the height of the 2-nd tree should be larger than the height of the first tree by 1, and so on. In other words, the heights of the trees, standing at equal distance from the edge (of one end of the sequence) must be equal to each other, and with the increasing of the distance from the edge by 1 the tree height must also increase by 1. For example, the sequences "2 3 4 5 5 4 3 2" and "1 2 3 2 1" are beautiful, and '1 3 3 1" and "1 2 3 1" are not.

Changing the height of a tree is a very expensive operation, using advanced technologies invented by Berland scientists. In one operation you can choose any tree and change its height to any number, either increase or decrease. Note that even after the change the height should remain a positive integer, i. e, it can't be less than or equal to zero. Identify the smallest number of changes of the trees' height needed for the sequence of their heights to become beautiful.

Input

The first line contains integer n (1 ≤ n ≤ 105) which is the number of trees. The second line contains integers ai (1 ≤ ai ≤ 105) which are the heights of the trees.

Output

Print a single number which is the minimal number of trees whose heights will have to be changed for the sequence to become beautiful.

Examples
input
32 2 2
output
1
input
41 2 2 1
output
0

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>using namespace std;const int maxn=100010;int num[maxn];int vis[maxn];int main(){    int n,k,ans=0;    scanf("%d",&n);    for(int i=1;i<=n;++i){        scanf("%d",&num[i]);    }    int mid=n/2+n%2;    for(int i=1;i<=mid;++i){        if(num[i]-i+1>0){            vis[num[i]-i+1]++;        }    }    for(int i=n;i>mid;--i){        if(num[i]+i-n>0){            vis[num[i]+i-n]++;        }    }    for(int i=1;i<=100000;++i){        ans=max(ans,vis[i]);    }    printf("%d\n",n-ans);    return 0;}


0 0
原创粉丝点击