Codeforces Round #260 (Div. 2) (DP没学好。。)

最近变懒了哎= =这是八号的比赛。又2题。

A. Laptops

题意:给出n台电脑的价格和质量。问是否存在2台电脑A,B满足: A的价格严格低于B,但A的质量严格高于B。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct dd{
    int a,b;
};
dd lap[100005];
char str[2][100]={"Happy Alex","Poor Alex"};
bool cmp(dd s,dd t){
    if(s.a!=t.a)
        return s.a<t.a;
    return s.b>t.b;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d%d",&lap[i].a,&lap[i].b);
    sort(lap,lap+n,cmp);//按价格从小到大排序
    bool tag=false;
    for(int i=1;i<n;i++){
        if(lap[i].b<lap[i-1].b&&lap[i].a>lap[i-1].a){
            tag=true;
            break;
        }
    }
    if(tag)
        printf("%s\n",str[0]);
    else
        printf("%s\n",str[1]);
    return 0;
}

B. Fedya and Maths

题意:(1n + 2n + 3n + 4nmod 5输入n,求上式。

思路:本来以为拿快速幂来求。但是发现n的范围太大来。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long ll;
char str[10000005];
int main(){
    scanf("%s",str);
    int len=strlen(str);
    if(len==1){//特判一位数
        int x=str[0]-'0';
        if(x%4==0)
            printf("4\n");
        else
            printf("0\n");
    }
    else{
        int x=(str[len-1]-'0')+10*(str[len-2]-'0');//满足被4整除的话只需考虑最后2位即可
        if(x%4==0)
            printf("4\n");
        else
            printf("0\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值