Codeforences #351 VK CUP

Source: Internet
Author: User

"A. Bear and Game:"

"Test Instructions" give so much time point, these time point is the point of interesting, if 15 minutes without appearing interesting point, will change; Ask the longest to see more time

"Analysis" can be simulated directly.

"AC Code"

#include <bits/stdc++.h>using namespace Std;int a[100];int main () {    int n;    while (~SCANF ("%d", &n)) {for        (int i=1; i<=n; i++) {            scanf ("%d", &a[i]);        }        if (a[1]>15) {            puts ("" ");            return 0;        }        for (int i=2; i<=n; i++) {            if (a[i]-a[i-1]>15) {                printf ("%d\n", a[i-1]+15);                return 0;            }        }        if (a[n]<75)        {            cout<<a[n]+15<<endl;        }        else{            cout<< "<<endl;}"    return 0;}

"B. Problems for Round"

"Test Instructions" put 1 to n these numbers into two containers, requiring that any number in the first container is less than any number in the second container, there is similar can not put a piece, similar to no transitivity

"Analysis" two containers the first record the maximum, the second record the minimum, for each pair similar to the number, small placed in the first, large in the second, while detecting whether to meet the maximum minimum value, but also to update the maximum minimum, the answer is the difference between the two!

"AC Code"

#include <bits/stdc++.h>using namespace std;int a[100010];const int INF = 0x3f3f3f3f;int Main () {    int n,m,u,v, Maxx=-1,minn=inf,ans;    cin>>n>>m;    for (int i=1; i<=m; i++) {        cin>>u>>v;        if (u>v) swap (u,v);        Maxx = max (maxx,u);        Minn = min (minn,v);    }    if (m==0) ans=n-1;    else{            if (minn<maxx) ans=0;            else ans = minn-maxx;    }    cout<<ans<<endl;    return 0;}

"C. Bear and Colors"

"Test Instructions" gives so many colors, in a sequence, the dominant is the number of occurrences of the most, if more than one occurrence, then the number of the smallest

"Analysis" can be a direct force statistic.

"AC Code"

#include <bits/stdc++.h>using namespace Std;int n,a[5010];int ans[5010];int temp;int Main () {    cin>>n;    for (int i=1; i<=n; i++) cin>>a[i];    for (int i=1; i<=n; i++) {        int cnt[5010]={0};        int maxx=-1;        for (int j=i; j<=n; J + +) {            cnt[a[j]]++;            if (Cnt[a[j]]>maxx) {                Maxx = cnt[a[j]];                temp = A[j];            } else if (cnt[a[j]]==maxx&&a[j]<temp) {                temp = a[j];            }            ans[temp]++;        }    }    for (int i=1; i<=n; i++) cout<<ans[i]<< "";    return 0;}

"D. Bear and both Paths"

The "test instructions" gives the n nodes, then gives the starting and ending points of the two routes, and asks you to construct a non-directed graph, so that there is no directly connected edge between A, B and c,d in the non-directed graph, and requires that the number of edges of this graph not exceed K

"Analysis" found n==4 when it is impossible to meet, you can construct such a graph, the first route ac...db; the second route ca...bd, such side is n+1, is the least

"AC Code"

#include <bits/stdc++.h>using namespace Std;int n,k,a,b,c,d;int ans[1010],vis[1010];int main () {    cin> >n>>k;    cin>>a>>b>>c>>d;    memset (vis,0,sizeof (Vis));    memset (ans,0,sizeof (ans));    Vis[a]=vis[b]=vis[c]=vis[d]=1;    if (k<n+1| | n==4) {        puts ("-1");        return 0;    }    ans[1]=a,ans[2]=c,ans[n-1]=d,ans[n]=b;    int pos=3;    for (int i=1; i<=n; i++) {        if (!vis[i]) ans[pos++]=i;    }    for (int i=1; i<=n; i++) cout<<ans[i]<< "";cout<<endl;    cout<<ans[2]<< "" <<ans[1]<< "";    for (int i=3; i<=n-2; i++) cout<<ans[i]<< "";    cout<<ans[n]<< "" <<ans[n-1]<<endl;    return 0;}

PS: The back of the question temporarily do not come Qaq "

Codeforences #351 VK CUP

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.