CF #151 div 2

Source: Internet
Author: User

The first four questions are simple, and the last one has not been done yet.
The first two questions are too easy to post code.
C. It was actually quite simple, but there was something wrong with it, and then it was hack, because it went to bed after an hour of competition and it was found that it was hack, so I tried to repeat the question and found that question A was still A little frustrated ..
Paste the code.
[Cpp]
Void solveC ()
{
Int n, k;
Cin> n> k;
For (int I = 0; I <n; I ++)
{
Scanf ("% d", & a [I]);
}
Sort (a, a + n );
Int num = 0;
For (int I = 0; I <n; I ++)
{
For (int j = n-i-1; j> = 0; j --)
{
Cout <I + 1;
For (int l = n-1; l> = n-I; l --)
{
Cout <"<a [l];
}
Cout <"" <a [j] <endl;
Num ++;
If (num> = k) break;
}
If (num> = k) break;
}
 
}

D.
[Cpp]
Struct kdq
{
Int u, v;
Int next;
} Edge [2, 1000005];
 
Int num = 0;
Int head [100005];
 
Void insert (int u, int v)
{
Edge [num]. u = u;
Edge [num]. v = v;
Edge [num]. next = head [u];
Head [u] = num ++;
}
Set <int> vv [100005];
Int vis [100005];
Void solveD ()
{
Int n, m;
Cin> n> m;
Memset (head,-1, sizeof (head ));
For (int I = 1; I <= n; I ++)
Scanf ("% d", & a [I]);
While (m --)
{
Int a1, b1;
Scanf ("% d", & a1, & b1 );
Insert (a1, b1 );
Insert (b1, a1 );
}
For (int I = 1; I <= n; I ++)
{
For (int j = head [I]; j! =-1; j = edge [j]. next)
{
Int v = edge [j]. v;
If (a [I]! = A [v]) // you cannot add points of the same color to this set.
Vv [a [I]. insert (a [v]);
}
}
Int ans =-1;
Int color =-1;
For (int I = 1; I <= n; I ++)
{
If (vis [a [I]) continue;
Int kk = vv [a [I]. size ();
If (kk> ans)
{
Ans = kk;
Color = a [I];
}
Else if (kk = ans)
{
If (color> a [I])
Color = a [I];
}
Vis [a [I] = 1;
}
Printf ("% d \ n", color );
}

E.

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.