Ultraviolet A 11063-B2-Sequence

Source: Internet
Author: User

Question: In {b1, b2,..., BK}, let's determine if the sum of any two numbers is different.

Analysis: number theory. Calculate all the results and sort them to determine whether the adjacent results are the same.

Note: Question 500 (⊙ _ ⊙ ).

#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int data[111];int sum[5555];int main(){int n,T = 1;while (~scanf("%d",&n)) {for (int i = 0 ; i < n ; ++ i)scanf("%d",&data[i]);int count = 0;for (int i = 0 ; i < n ; ++ i)for (int j = 0 ; j < i ; ++ j)sum[count ++] = data[i]+data[j];sort(sum, sum+count);int flag = 0;for (int i = 1 ; i < count ; ++ i)if (sum[i] == sum[i-1]) {flag = 1;break;}if (!flag)printf("Case #%d: It is a B2-Sequence.\n\n",T ++);else printf("Case #%d: It is not a B2-Sequence.\n\n",T ++);}return 0;}


Ultraviolet A 11063-B2-Sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.