A. Laptops
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).

Examples
input
  1. 2
    1 2
    2 1
output
  1. Happy Alex

题意:n个物品 a为价格 b为物品的质量 若满足价格越高质量越好 输出Poor Alex 反之输出Happy Alex

题解:水  注意结构体排序的一个细节....orz

  1. /******************************
  2. code by drizzle
  3. blog: www.cnblogs.com/hsd-/
  4. ^ ^ ^ ^
  5. O O
  6. ******************************/
  7. #include<bits/stdc++.h>
  8. #include<iostream>
  9. #include<cstring>
  10. #include<cstdio>
  11. #include<map>
  12. #include<algorithm>
  13. #include<queue>
  14. #define ll __int64
  15. using namespace std;
  16. int n;
  17. struct node
  18. {
  19. int a,b;
  20. }N[];
  21. bool cmp(struct node aa,struct node bb)
  22. {
  23. return aa.a<bb.a;
  24. }
  25. int main()
  26. {
  27. scanf("%d",&n);
  28. int flag=;
  29. for(int i=;i<n;i++){
  30. scanf("%d %d",&N[i].a,&N[i].b);
  31. if(N[i].a!=N[i].b)
  32. flag=;
  33. }
  34. if(flag)
  35. cout<<"Happy Alex"<<endl;
  36. else
  37. cout<<"Poor Alex"<<endl;
  38. return ;
  39. }
B. Fedya and Maths
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:

(1n + 2n + 3n + 4nmod 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).

Input

The single line contains a single integer n (0 ≤ n ≤ 10105). The number doesn't contain any leading zeroes.

Output

Print the value of the expression without leading zeros.

Examples
input
  1. 4
output
  1. 4
input
  1. 124356983594583453458888889
output
  1. 0
Note

Operation x mod y means taking remainder after division x by y.

Note to the first sample:

题意:计算(1n + 2n + 3n + 4nmod 5  n为次幂 n为大数

枚举n的值可以发现规律 只要n%4==0则输出4 否则输出0 剩下的问题就是大数对小数取模了

题解:大数对小数取模 从高位到低位 具体看代码

  1. /******************************
  2. code by drizzle
  3. blog: www.cnblogs.com/hsd-/
  4. ^ ^ ^ ^
  5. O O
  6. ******************************/
  7. #include<bits/stdc++.h>
  8. #include<iostream>
  9. #include<cstring>
  10. #include<cstdio>
  11. #include<map>
  12. #include<algorithm>
  13. #include<queue>
  14. #define ll __int64
  15. using namespace std;
  16. int n;
  17. char a[];
  18. int main()
  19. {
  20. cin>>a;
  21. n=strlen(a);
  22. int exm=;
  23. for(int i=;i<n;i++)
  24. {
  25. exm=exm*+a[i]-'';
  26. exm%=;
  27. }
  28. if(exm==)
  29. cout<<""<<endl;
  30. else
  31. cout<<""<<endl;
  32. return ;
  33. }
C. Boredom
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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).

Output

Print a single integer — the maximum number of points that Alex can earn.

Examples
input
  1. 2
    1 2
output
  1. 2
input
  1. 3
    1 2 3
output
  1. 4
input
  1. 9
    1 2 1 3 2 2 2 2 3
output
  1. 10
Note

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为结尾的所要求的最大值

  1. /******************************
  2. code by drizzle
  3. blog: www.cnblogs.com/hsd-/
  4. ^ ^ ^ ^
  5. O O
  6. ******************************/
  7. #include<bits/stdc++.h>
  8. #include<iostream>
  9. #include<cstring>
  10. #include<cstdio>
  11. #include<map>
  12. #include<algorithm>
  13. #include<queue>
  14. #define ll __int64
  15. using namespace std;
  16. int n;
  17. ll a[];
  18. ll dis[];
  19. ll ans[];
  20. int main()
  21. {
  22. scanf("%d",&n);
  23. memset(dis,,sizeof(dis));
  24. memset(ans,,sizeof(ans));
  25. for(int i=;i<=n;i++)
  26. {
  27. scanf("%I64d",&a[i]);
  28. dis[a[i]]++;
  29. }
  30. ans[]=dis[];
  31. for(int i=;i<=1e5;i++)
  32. ans[i]=max(ans[i-]+i*dis[i],ans[i-]);
  33. printf("%I64d\n",ans[]);
  34. return ;
  35. }

Codeforces Round #260 (Div. 2) A B C 水 找规律(大数对小数取模) dp的更多相关文章

  1. Codeforces Round #327 (Div. 2) C Median Smoothing(找规律)

    分析: 三个01组合只有八种情况: 000 s001 s010 0011 s100 s101 1110 s111 s 可以看出只有010,101是不稳定的.其他都是稳定的,且连续地出现了1或0,标记为 ...

  2. Codeforces Round #272 (Div. 2) D.Dreamoon and Sets 找规律

    D. Dreamoon and Sets   Dreamoon likes to play with sets, integers and .  is defined as the largest p ...

  3. DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) ...

  4. 递推DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...

  5. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  6. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  7. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  8. Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Codeforces Round #260 (Div. 2)AB

    http://codeforces.com/contest/456/problem/A A. Laptops time limit per test 1 second memory limit per ...

随机推荐

  1. JobTracker启动流程源码级分析

    org.apache.hadoop.mapred.JobTracker类是个独立的进程,有自己的main函数.JobTracker是在网络环境中提交及运行MR任务的核心位置. main方法主要代码有两 ...

  2. visual studio 2013连接Oracle 11g并获取数据:(二:实现)

    1.VS中新建一个winform窗体 (1)一个按钮 (2)一个数据表格视图(在里面显示得到的数据表) 2.双击按钮进入代码 (1)添加 using System.Data.OracleClient; ...

  3. HTML5中canvas的save和restore方法

    canvas的save和restore方法: save() 方法把当前绘画状态的一份拷贝压入到一个保存图像状态的栈中.这里的绘画状态指坐标原点.变形时的变化矩阵(该矩阵是调用 rotate().sca ...

  4. HDU 5451 广义斐波那契数列

    这道题目可以先转化: 令f(1) = 5+2√6 f(2) = f(1)*(5+2√6) ... f(n) = f(n-1)*(5+2√6) f(n) = f(n-1)*(10-(5-2√6)) = ...

  5. <转>提高iOS开发效率的方法和工具

    介绍 这篇文章主要是介绍一下我在iOS开发中使用到的一些可以提升开发效率的方法和工具. IDE 首先要说的肯定是IDE了,说到IDE,Xcode不能跑,当然你也可能同时在使用AppCode等其他的ID ...

  6. java udp网络编程

    import java.net.*; /* 通过UDP传输发送文字数据 1.建立socket服务 2.提供数据,并封装到数据包中 3.通过sokect服务的发送功能,将数据包发送出去 4.关闭资源 * ...

  7. android 原生dialog对话框

    http://www.cnblogs.com/xiaoluo501395377/p/3419398.html

  8. [Java]eclipse的使用

    1.android sdk help安装 使用SDK Manager.exe下载android sdk的时候把docs也勾选上. 在eclipse的android工程下的android.jar(在an ...

  9. 加强版for循环

    /*加强版for循环 * 5.0以后有加强版for循环 * for(String name:nameArray){} * 1.String name:声明会带有数组单一元素的循环变量 *   数组元素 ...

  10. JAVA工作方式

    public class Hellow { int eyes = 2; int ears = 2; int legs = 4; void run(){ //方法 System.out.println( ...