Bob is developing a new game called jumping Lario. In this game the main protagonist, Lario, has to jump on top of buildings until he reaches the end of the level. The level is composed of N buildings of possibly different heights. The building where Lario starts is chosen randomly at the beginning of the game.
Bob started to write the code for his game but then realized that he didn't know how to implement the jumps mechanics. The thing is, if Lario is currently on top of building X and the height of this building is h, then Lario should be able to reach building min(X + h, n) in one jump. Unless, of course, there's a taller building somewhere on the path from building X to building X + h, then in this case, Lario would face smash the taller building on the path and end up landing right before it.
For example, in the image bellow, if Lario had started on the first building (of height 5), with one jump he should be able to reach building six. But on the path from building one to building six, he would end up hitting building five that has height 6. When doing so, he would land on building four (the one with height 3).
Given the heights for all the N buildings, your task is to figure out for every possible start position of Lario, how far he would be able to go with just one jump.
Input
The first line of the input contains a single integer N (1 ≤ N ≤ 105), indicating the number of buildings.
The second line of the input contains N integers h1, h2... hN (1 ≤ hi ≤ 105), indicating the height of each building.
Output
Output N integers. The i-th integer indicating the farthest building that Lario can reach with one jump if he starts on top of the i-th building.
Example
Input
6
5 2 2 3 6 2
Output
3 1 0 0 1 0
AC代码
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int maxn = 1e5+10;
int a[100005];
int main()
{
int n;
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>a[i];
}
int ans[maxn];
for(int i=1; i<=n; i++)
{
int k = min(i+a[i],n);
int flag=0;
for(int j=i+1; j<=k; j++)
{
if(a[j]>a[i])
{
ans[i] = j-i-1;
// cout<<ans[i]<<endl;
flag=1;
break;
}
}
if(!flag)
{
ans[i] = k-i;
}
}
for(int i=1; i<=n; i++)
{
if(i==1)
cout<<ans[i];
else
cout<<' '<<ans[i];
}
cout<<endl;
return 0;
}
队友爆发,一次过,躺了;
After your death, you’re sent to a mysterious room. There are two guardian cats and two doors, one goes to heaven of AC problems and another goes to hell NO. One cat likes all divisors of an integer a and the other cat likes all multiples of an integer b. You where asked to write all integers that satisfies both. If you answer correctly, you may go to heaven of AC problems, full of balloons, otherwise you’re sent to hell NO.
Input
The input consists of two integers a and b, where 1 ≤ b ≤ a ≤ 1012.
Output
The output consists of one line with all integers from smallest to largest that satisfies both guardian cats.
Examples
Input
12 3
Output
3 6 12
Input
10 3
Output
Input
128 2
Output
2 4 8 16 32 64 128
ac代码
#include <bits/stdc++.h>
using namespace std;
const int manx=1e5;
long long a,b;
long long s1[manx];
long long s2[manx];
int main()
{
int k=1;
long long i;
scanf("%lld %lld",&a,&b);
for(i=1; i<=sqrt(a); i++)
{
if(a%i==0)
{
s1[k++]=i;
if(a/i!=i) s1[k++]=a/i;
}
}
int x=1;
for( i=1; i<k; i++)
{
if(s1[i]%b==0)
{
s2[x++]=s1[i];
}
}
sort(s2+1,s2+x);
for( i=1; i<x; i++)
{
if(i==x-1) printf("%lld",s2[i]);
else printf("%lld ",s2[i]);
}
return 0;
}
注意当开放后,能够开出来的数会进栈两次,要排除一次;
Samuelo is a very good friend of Roppa. Whenever they feel bored, they like to exchange secret messages.
To do that, they craft some text in such a way so that the hidden message is a subsequence of it. To make things harder, they never use whitespaces.
An example of message exchanged in the past is (hidden message is red and underlined):
It can be very hard to uncover a message hidden like that, but it's usually not a problem for them since their minds are pretty much in sync.
Samuelo just wrote one of those messages. Roppa decided to take a step further this time and test their friendship by trying to guess the hidden message before even receiving it.
Given the message that Samuelo wrote and Roppa's guess, help Roppa on figuring out if his guess is in fact hidden in Samuelo's message.
Input
The first line the input contains a string s
(1≤|s|≤106), indicating the message that Samuelo wrote. The second line of the input contains a string t (1≤|t|≤106
), indicating Roppa's guess.
Both strings are composed only of lowercase English letters.
Output
Output YES if Roppa's guess is hidden in Samuelo's message. Otherwise, output NO.
Examples
Input
threeyellowfurryfiends
hellofriend
Output
YES
Input
hardcontest
easyac
Output
NO
大水题,直接暴力遍历
You have a box with N cards numbered 1…N and you can also create new cards.
You are going to draw cards from the box, every time you draw a card of a number that has already been drawn you put that card back into the box. If you draw a card of a number that has not been drawn before, you lay it on the desk and you create another card to put back into the box. The number of the new card is chosen randomly with the same probability from the interval [1, N].
In this problem you have to answer what is the expected number of cards on the desk when you draw a card numbered 1 for the first time.
Input
One integer N (1 ≤ N ≤ 106).
Output
One floating point number, the expected number of cards on the desk when a card with the number 1 is drawn for the first time. Your answer will be considered correct if the absolute and relative error compared with the judge's solution is less than 10 - 4.
Example
Input
2
Output
1.5000000000
怎么硕呢,做人就要大胆吧,直接按案例凑,直接过;
Tomaz and Danftito are playing a game with 3 stacks of rocks, each with a, b and c rocks respectively. Each turn, a player must take from 1 to m rocks from a stack, but they can't empty a stack if there are rocks in any stack to the left. The player that removes the last rock wins. If Tomaz goes first and they take turns playing, determine who will win the game if both players play optimally.
Input
The input contains one line with four integers: m (1 ≤ m ≤ 1018) representing the maximum amount of rocks to be removed in a single turn, a, b and c (1 ≤ a, b, c ≤ 1018) each representing how many rocks there are initially in the first, second and third stacks respectively.
Output
Print "Tomaz" if Tomaz will win the game, and "Danftito" otherwise.
Example
Input
3 1 1 1
Output
Tomaz
#include <bits/stdc++.h>
using namespace std;
long long n,a,b,c,s1,s2,s3;
int main()
{
scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
s1=a%(n+1);
s2=(b-1)%(n+1);
s3=(c-1)%(n+1);
if((s1^s2^s3)==0)
printf("Danftito\n");
else
printf("Tomaz\n");
return 0;
}
博弈还不太行,回去好好研究,队友过的;