1 second
256 megabytes
standard input
standard output
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops.
Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality).
All ai are distinct. All bi are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
2
1 2
2 1
Happy Alex
题意:n个物品 a为价格 b为物品的质量 若满足价格越高质量越好 输出Poor Alex 反之输出Happy Alex
题解:水 注意结构体排序的一个细节....orz
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n;
struct node
{
int a,b;
}N[];
bool cmp(struct node aa,struct node bb)
{
return aa.a<bb.a;
}
int main()
{
scanf("%d",&n);
int flag=;
for(int i=;i<n;i++){
scanf("%d %d",&N[i].a,&N[i].b);
if(N[i].a!=N[i].b)
flag=;
}
if(flag)
cout<<"Happy Alex"<<endl;
else
cout<<"Poor Alex"<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
The single line contains a single integer n (0 ≤ n ≤ 10105). The number doesn't contain any leading zeroes.
Print the value of the expression without leading zeros.
4
4
124356983594583453458888889
0
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
题意:计算(1n + 2n + 3n + 4n) mod 5 n为次幂 n为大数
枚举n的值可以发现规律 只要n%4==0则输出4 否则输出0 剩下的问题就是大数对小数取模了
题解:大数对小数取模 从高位到低位 具体看代码
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n;
char a[];
int main()
{
cin>>a;
n=strlen(a);
int exm=;
for(int i=;i<n;i++)
{
exm=exm*+a[i]-'';
exm%=;
}
if(exm==)
cout<<""<<endl;
else
cout<<""<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105).
Print a single integer — the maximum number of points that Alex can earn.
2
1 2
2
3
1 2 3
4
9
1 2 1 3 2 2 2 2 3
10
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this[2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
题意:给你n个值 每次取出一个值ak 则删除所有的ak +1 ,ak -1 一直到最后一个数
输出 取出的值的和的最大值
题解:这n个值的范围为1 ≤ ai ≤ 10^5 先标记 记录每个数i出现的次数dis[i]
转移方程 dp[i]=max(dp[i-2]+i*dis[i],dp[i-1]) 也就是相当于判断当前这个数是被删除?还是被取出?
i*dis[i]表示数i对结果的贡献 dp[i]代表以i为结尾的所要求的最大值
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n;
ll a[];
ll dis[];
ll ans[];
int main()
{
scanf("%d",&n);
memset(dis,,sizeof(dis));
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i]);
dis[a[i]]++;
}
ans[]=dis[];
for(int i=;i<=1e5;i++)
ans[i]=max(ans[i-]+i*dis[i],ans[i-]);
printf("%I64d\n",ans[]);
return ;
}