hihocoder 1223 不等式

比赛的时候并没有想到x可能是小数,只能说自己的思维不够活跃,
然后也并没有想到这道题目可以通过枚举取哪一个数,然后对给出的情况判断是否符合

#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf -0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
char s[51];
char s1[51][10];
int a[51];

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%s%s%d",s,s1[i],&a[i]);
            a[i]*=2;        //因为x可能为小数
        }
        int count1=0;
        for(int i=-1;i<=2001;i++){
            int cnt=0;
            for(int j=1;j<=n;j++){
                if(strcmp(s1[j],"<=")==0){
                    if(a[j]>=i)
                        cnt++;
                }
                if(strcmp(s1[j],">=")==0){
                    if(a[j]<=i)
                        cnt++;
                }
                if(strcmp(s1[j],"<")==0){
                    if(a[j]>i)
                        cnt++;
                }
                if(strcmp(s1[j],">")==0){
                    if(a[j]<i)
                        cnt++;
                }
                if(strcmp(s1[j],"=")==0){
                    if(a[j]==i)
                        cnt++;
                }
            }
            count1=max(count1,cnt);
        }
        printf("%d\n",count1);
    }
    return 0;
}
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf -0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
char s[51];
char s1[51][10];
int a[51];

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%s%s%d",s,s1[i],&a[i]);
            a[i]*=2;        //因为x可能为小数
        }
        int count1=0;
        for(int i=-1;i<=2001;i++){
            int cnt=0;
            for(int j=1;j<=n;j++){
                if(strcmp(s1[j],"<=")==0){
                    if(a[j]>=i)
                        cnt++;
                }
                if(strcmp(s1[j],">=")==0){
                    if(a[j]<=i)
                        cnt++;
                }
                if(strcmp(s1[j],"<")==0){
                    if(a[j]>i)
                        cnt++;
                }
                if(strcmp(s1[j],">")==0){
                    if(a[j]<i)
                        cnt++;
                }
                if(strcmp(s1[j],"=")==0){
                    if(a[j]==i)
                        cnt++;
                }
            }
            count1=max(count1,cnt);
        }
        printf("%d\n",count1);
    }
    return 0;
}

你可能感兴趣的:(hihocoder 1223 不等式)