cf#345 Div2 a\b\c problem

Source: Internet
Author: User

Question A:

Greedy water problem, pay attention to this group of data, pit a lot of people

Question B:

Sort the array first, and then the problem can be abstracted to find the maximum number of ascending sub-sequences of an ordered array, and the implementation is a bit clumsy (I'd rather call it ingenious:))

#include <iostream> #include <cstring> #include <algorithm> #define INF 99999using namespace Std;int Num[1007][1007];int Main () {int n;int a[1007];while (cin>>n) {int ans = 0;memset (num,0,sizeof (num)); for (int i = 1;i & lt;= n;i++) Cin>>a[i];sort (a+1,a+1+n);//Initialize first int cnt = 0;int Min = inf;num[1][++cnt]++;int tmp = a[1];for (int i = 2 ; I <= n;i++) {if (a[i] = = tmp) num[1][cnt]++;else {tmp = a[i];num[1][++cnt]++;}}  for (int i = 1;i <= cnt;i++) min = min (min,num[1][i]), int y = 1;while (cnt) {ans + = (cnt-1) *min;int tcount = 0;for (int i = 1;i <= cnt;i++) {num[y][i]-= Min;if (Num[y][i]) num[y+1][++tcount] = Num[y][i];} CNT = tcount;y++; min = inf;for (int i = 1;i <= cnt;i++) min = min (min,num[y][i]);} Cout<<ans<<endl;} return 0;}

Question C:

The calculation formula of the two can be deduced to find any two points to meet the requirements, as long as xy two coordinates as long as the (x| | Y) The compound proposition is true. Then as for the size of the array, here reference a special data structure to store a large amount of data, and then note that x or Y coordinates have the same n points, and ans is to add or subtract n (n-1)/2

cf#345 Div2 a\b\c problem

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.