(2016弱小联盟十一专场10.3) Best Matched Pair 暴力
来源:互联网 发布:sql delete from table 编辑:程序博客网 时间:2024/06/05 03:47
Best Matched Pair
Input: Standard Input
Time Limit: See AtCoder
You are working for a worldwide game company as an engineer in Tokyo. This company holdsan annual event for all the staff members of the company every summer. This year’s event will take place in Tokyo. You will participate in the event on the side of the organizing staff. Andyou have been assigned to plan a recreation game which all the participants will play at the same time.
After you had thought out various ideas, you designed the rules of the game as below.
Each player is given a positive integer before the start of the game.
Each player attempts to make a pair with another player in this game, and formed pairs
compete with each other by comparing the products of two integers.
Each player can change the partner any number of times before the end of the game, but
cannot have two or more partners at the same time.
At the end of the game, the pair with the largest product wins the game.
In addition, regarding the given integers, the next condition must be satised for making a pair.
The sequence of digits obtained by considering the product of the two integers of a pair
as a string must be increasing and consecutive from left to right. For example, 2, 23, and
56789 meet this condition, but 21, 334, 135 or 89012 do not.
Setting the rules as above, you noticed that multiple pairs may be the winners who have the
same product depending on the situation. However, you can nd out what is the largest product
of two integers when a set of integers is given.
Your task is, given a set of distinct integers which will be assigned to the players, to compute
the largest possible product of two integers, satisfying the rules of the game mentioned above.
Input
The input consists of a single test case formatted as follows.
1
N
a1 a2 … aN
The rst line contains a positive integer N which indicates the number of the players of the
game. N is an integer between 1 and 1; 000. The second line has N positive integers that
indicate the numbers given to the players. For i = 1; 2;…;N -1, there is a space between ai
and ai+1. ai is between 1 and 10; 000 for i = 1; 2; : : : ;N, and if i ̸= j, then ai ̸= aj .
Output
Print the largest possible product of the two integers satisfying the conditions for making a pair.
If any two players cannot make a pair, print -1.
Sample Input 1
2
1 2
Output for the Sample Input 1
2
Sample Input 2
3
3 22 115
Output for the Sample Input 2
345
Sample Input 3
2
1 11
Output for the Sample Input 3
-1
Sample Input 4
2
5 27
Output for the Sample Input 4
-1
Sample Input 5
2
17 53
Output for the Sample Input 5
-1
Sample Input 6
10
53 43 36 96 99 2 27 86 93 23
Output for the Sample Input 6
3456
题意:
给你n个数,求任意两个数的乘积是一个连续递增的数的最大值,若不存在输出-1
分析:
由于n<=1000,所以可以直接暴力
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;int n,a[1010];char str[10];bool pd(int s){ int len = 0; while(s) { str[len++] = s%10+'0'; s = s/10; } for(int i=0;i<len-1;i++) if(str[i]!=str[i+1]+1) return false; return true;}int main(){ while(scanf("%d",&n)!=EOF) { int ans = -1; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { int tmp = a[i]*a[j]; if(pd(tmp) && tmp > ans) ans = tmp; } } printf("%d\n",ans); } return 0;}
- (2016弱小联盟十一专场10.3) Best Matched Pair 暴力
- 2016弱校联盟十一专场10.3 ABest Matched Pair(水)
- (2016弱小联盟十一专场10.3)Parentheses 找规律
- (2016弱小联盟十一专场10.3) Help the Princess! BFS
- Coins(弱小联盟十一专场)
- Aizu 2780 Best Matched Pair
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校联盟十一专场10.3,BNU52308,大模拟
- (2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci (暴力 + 循环节)
- BNU Problem A Best Matched Pair
- 2016 ACM-ICPC Asia Regional A – Best Matched Pair(打表)
- 2016弱校联盟十一专场10.3 C.We don't wanna work!(集合操作)
- 2016弱校联盟十一专场10.3 We don't wanna work!
- (2016 弱校联盟十一专场10.3) Similarity of Subtrees DFS + hash
- 2016弱校联盟十一专场10.2 Longest Increasing Subsequence
- [Contests]2016弱校联盟十一专场10.7
- [JAG practice] A - Best Matched Pair 遍历+水题
- Blocks(弱校联盟十一专场)
- 面试问题及回答技巧
- 自定义控件——ListView下拉刷新和上拉加载
- Linux命令之"iostat"
- Android之数据存储详解(二)之SQLite数据库存储数据
- 二分查找和二分排序
- (2016弱小联盟十一专场10.3) Best Matched Pair 暴力
- 欢迎使用CSDN-markdown编辑器
- QT中QLineEdit的editingFinished()信号在按下回车时会触发两次的解决办法
- Akamai CDN技术调研
- 34 韩信点兵
- swift 的if语句,switch语句,元组,函数
- CxImage
- EagleGet - 猎鹰,视频下载的神器
- Shape