Codeforces Round#497(Div.2)

Codeforces Round#497(Div.2)

A罗马字(Romaji )

这道题比较水吧,直接暴力判断即可。其中“n”在里面一重循环特殊判断就行了。代码附上

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int check(char c){
    if(c=='a' || c=='o' || c=='u' || c=='i' || c=='e') return 1;
    else return 0;
}
int main(){
    string s;cin>>s;
    for(int i=0;i<s.length();i++)
        if(!check(s[i]) && s[i]!='n')
            if(!check(s[i+1]) || i+1>s.length()-1){
                puts("NO");
                return 0;
            }
    puts("YES");
    return 0;
} 

B转动矩阵(Turn the Rectangles )

这道题贪心水掉,注意判等于的情况,把每个矩阵两种高度记录下来,然后贪心往高算。其中如果有个矩阵的最小高仍然大于之前的高,则不合法

#include<cstdio>
#include<algorithm>
#define maxn 100010
using namespace std;
int a[maxn],b[maxn];

int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d %d",&a[i],&b[i]); 
    int pre=2e9;
    for(int i=1;i<=n;i++){
        if(a[i]>b[i]) swap(a[i],b[i]);
        if(a[i]>pre){
            puts("NO");
            return 0;
        }
        if(b[i]<=pre) pre=b[i];
        else pre=a[i];
    }
    puts("YES");
    return 0;
} 

C 重新排序阵列(Reorder the Array)

嗯,这道题有点意思。我首先先想到把每个点放入桶中,离散化后求出每个点在序列中有几个比它大的点,然后一个个与经过排序的原序列比对,放入数据。显然比较麻烦。推到一下可以发现每个点可以直接sort求出序列位置,省区离散化步骤。basort好的序列从大到小与自己后i位匹配就好了。语言表达能力有问题,代码还是清晰的

#include<cstdio>
#include<algorithm>
using namespace std;
int a[100010];
int cmp(int a,int b){return a>b;}
int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1,cmp);
    int ans=1;
    for(int i=2;i<=n;i++)
        if(a[ans]>a[i]) ans++;
    printf("%d",ans-1);
} 

猜你喜欢

转载自blog.csdn.net/ykhrg/article/details/81046387