best matched pair

今天的模拟赛,被虐的不行。。。。英文太差,弄不懂题意,弄懂题意了还不会。。。

感觉快要受不了了。。。

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int judge(int t){
    int intge[15];
    int cou=0;
    while(t>=10){
        int p=t%10;
        t/=10;
        intge[cou++]=p;
    }
    intge[cou++]=t;
    for(int i=0;i<cou-1;i++){
        if(intge[i]<=intge[i+1]||(intge[i]-intge[i+1])!=1){
            return 0;
        }
    }

    return 1;
}

int main()
{
    int n;
    int a[1005];
    int b=0;
    while(scanf("%d",&n)!=EOF){
        b=0;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(j!=i){
                    int t=a[j]*a[i];
                    if(judge(t)&&b<t){
                        b=t;
                    }
                }
            }
        }
        if(b==0){
            printf("-1\n");
        }else{
            printf("%d\n",b);
        }
    }
    return 0;
}
时间: 2024-08-24 14:43:05

best matched pair的相关文章

(2016弱校联盟十一专场10.3) A.Best Matched Pair

题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> using namespace std; int n,data[1005]; int cal(int x) { int tx=x; int pre=-1; while(tx) { if(pre!=-1&&tx%10-pre!=-1) return -1; pre = tx%10; tx/=10

弱校连萌 10.3

A.Best Matched Pair B.Help the Princess! C.We don't wanna work! D.Parentheses E.Similarity of Subtrees F.Escape from the Hell G.Share the Ruins Preservation H.Pipe Fitter and the Fierce Dogs I.Multisect J.Compressed Formula K.Non-redundant Drive

DRAM 内存介绍(二)

参考资料:http://www.anandtech.com/show/3851/everything-you-always-wanted-to-know-about-sdram-memory-but-were-afraid-to-ask/4   The process of moving data in and out of the Memory Array and over the Memory Bus is not overly complicated, although the massi

弱校联盟10.3

Problem A. Best Matched Pair 找出最大的每一位递增1的一对乘积,$n^2$枚举 #include<bits/stdc++.h> using namespace std; int n,a[2000],ans=-1; bool ck(int a){ int b=-1; while(a){ int t=a%10;//23456 a/=10; if(b!=-1&&t!=b-1)return 0; b=t; } return 1; } int main(){

Transistor 晶体管 场效应 双极型 达林顿 CMOS PMOS BJT FET

Transistor Tutorial Summary Transistor Tutorial Summary Bipolar Junction Transistor Tutorial We can summarise this transistors tutorial section as follows: The Bipolar Junction Transistor (BJT) is a three layer device constructed form two semiconduct

POJ #1141 - Brackets Sequence - TODO: POJ website issue

A bottom-up DP. To be honest, it is not easy to relate DP to this problem. Maybe, all "most"\"least" problems can be solved using DP.. Reference: http://blog.sina.com.cn/s/blog_8e6023de01014ptz.html There's an important details to AC:

Labeled Faces in the Wild 人脸识别数据集

http://blog.csdn.net/garfielder007/article/details/51480525 New (draft) survey paper: Labeled Faces in the Wild: A SurveyErik Learned-Miller, Gary Huang, Aruni RoyChowdhury, Haoxiang Li, Gang Hua The camera-ready has not yet been submitted. If you se

C++学习 之pair

Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型,第一个元素是int型的,第二个元素是string类型的,如果创建pair的时候没有对其进行初始化,则调用默认构造函数对其初始化. pair<string, string> a("James", "Joy"); 也可以像上面一样在定义的时候直接对其初始化. 由于pair类型的使用比

C++ STL pair详解

一.解释: p { margin-bottom: 0.25cm; direction: ltr; color: #00000a; line-height: 120%; text-align: left; orphans: 2; widows: 2 } p.western { font-family: "Liberation Serif", serif; font-size: 12pt } p.cjk { font-family: "Noto Sans CJK SC Regul