CF #260 (Div. 2)A

Laptops
time limit per test
1 second
memory limit per test
256 megabytes

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

Sample test(s)
Input
2
1 2
2 1
Output
Happy Alex
 
   
 
   
 
   
 
   
解题思路:
    题意是说输入n,然后n行,每行两个数a和b,代表笔记本的价格和质量。Alex认为价格便宜的质量也有可能高,
如果Alex说得对,输出Happy Alex,否则输出Poor Alex。
    开个结构体,输入完后把价格a按从小到大排个序,然后遍历,如果发现后者的质量比前者的小,那么flag置为
1,说明Alex说得对。
 
   
 
   
 
   
 
   
 
   
 
   
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>


using namespace std;

#define REP(i, n) for (int i=0;i<n;++i)
#define FOR(i, a, b) for (int i=a;i<b;++i)
#define DWN(i, b, a) for (int i=b-1;i>=a;--i)
#define REP_1(i, n) for (LL i=1;i<=n;++i)
#define FOR_1(i, a, b) for (int i=a;i<=b;++i)
#define DWN_1(i, b, a) for (LL i=b;i>=a;--i)
#define REP_C(i, n) for (int n____=n,i=0;i<n____;++i)
#define FOR_C(i, a, b) for (int b____=b,i=a;i<b____;++i)
#define DWN_C(i, b, a) for (int a____=a,i=b-1;i>=a____;--i)
#define REP_N(i, n) for (i=0;i<n;++i)
#define FOR_N(i, a, b) for (i=a;i<b;++i)
#define DWN_N(i, b, a) for (i=b-1;i>=a;--i)
#define REP_1_C(i, n) for (int n____=n,i=1;i<=n____;++i)
#define FOR_1_C(i, a, b) for (int b____=b,i=a;i<=b____;++i)
#define DWN_1_C(i, b, a) for (int a____=a,i=b;i>=a____;--i)
#define REP_1_N(i, n) for (i=1;i<=n;++i)
#define FOR_1_N(i, a, b) for (i=a;i<=b;++i)
#define DWN_1_N(i, b, a) for (i=b;i>=a;--i)
#define REP_C_N(i, n) for (int n____=(i=0,n);i<n____;++i)
#define FOR_C_N(i, a, b) for (int b____=(i=0,b);i<b____;++i)
#define DWN_C_N(i, b, a) for (int a____=(i=b-1,a);i>=a____;--i)
#define REP_1_C_N(i, n) for (int n____=(i=1,n);i<=n____;++i)
#define FOR_1_C_N(i, a, b) for (int b____=(i=a,b);i<=b____;++i)
#define DWN_1_C_N(i, b, a) for (int a____=(i=b,a);i>=a____;--i)

#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define REP_S(i, str) for (char*i=str;*i;++i)
#define REP_L(i, hd, suc) for (int i=hd;i;i=suc[i])
#define REP_G(i, u) REP_L(i,hd[u],suc)
#define REP_SS(x, s) for (int x=s;x;x=(x-1)&s)
#define DO(n) for ( int ____n = n; ____n-->0; )
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)
#define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)
#define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)

#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define LBD(A, x) (lower_bound(ALL(A), x) - A.begin())
#define UBD(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int((A).size())

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;

/** Constant List .. **/ //{

const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;

struct node
{
    int a , b;
}q[1000010];


bool cmp(node x , node y)
{
    return x.a < y.a;
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 0 ; i < n ; i ++)
            scanf("%d%d",&q[i].a , &q[i].b);
        sort(q , q + n , cmp);
        int flag = 0;
        for(int  i = 1 ; i < n ; i ++)
        {
            if(q[i - 1].b > q[i].b )
            {
                flag = 1;
                break;
            }
        }
        if(flag)
            printf("Happy Alex\n");
        else
            printf("Poor Alex\n");
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="com.test.bean.Goods,java.util.ArrayList" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>购物车</title> <style type="text/css"> table{border-collapse:collapse;} td{border:1px solid black; text-align:center; } #deal{margin-left:200px} </style> </head> <body> <jsp:useBean id="cart" class="com.test.bean.Cart" scope="session"></jsp:useBean> <%if(cart==null||cart.getGoodslist().size()==0) out.println("购物车空空如也.....<a href='index.jsp'>返回商品首页</a>"); else{ ArrayList<Goods>goodslist=cart.getGoodslist(); %> <div> 当前购物车共有<%=cart.getGcount() %>件物品    <a href='index.jsp'>返回商品首页</a><br> <table><tr> <td>序号</td> <td>商品号</td> <td>商品名称</td> <td>价格</td> <td>数量</td> <td>小计</td> <td>描述</td></tr> <%for(int i=0;i<goodslist.size();i++){ Goods goods=goodslist.get(i); %> <tr> <td><%=i+1 %></td> <td><%=goods.getGid() %></td> <td><%=goods.getGname() %></td> <td><%= String.format("%.2f", goods.getGprice())%></td> <td><%=goods.getGcount() %></td> <td><%=String.format("%.2f", goods.getGprice()*goods.getGcount()) %></td> <td><a href="<%=request.getContextPath() %>/Servlet/DelCartServlet?gid=<%=goods.getGid() %>">删除</a></td></tr> <%}%> </table><br> <span>总计</span><%=String.format("%.2f",cart.getTotal())%>    <input type="button" id="deal" value="购买" /></input> </div> <%}%> <script type="text/javascript"> var dealbutton=document.getElementById("deal"); dealbutton.onclick=function(){ var cf=confirm("确定购买吗?"); if(cf==true){ window.location.href="Servlet/DealServlet"; } } </script> </body> </html> 修改删除功能,在购物车物品数量大于1的情况下点击“删除”时减少1个,等于1时删除此项商品;
最新发布
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值