zoukankan      html  css  js  c++  java
  • Round #452(Div 2)

    A. Splitting in Teams
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.

    The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.

    Input

    The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.

    The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.

    Output

    Print the maximum number of teams of three people the coach can form.

    Examples
    input
    4
    1 1 2 1
    output
    1
    input
    2
    2 2
    output
    0
    input
    7
    2 2 2 1 1 1 1
    output
    3
    input
    3
    1 1 1
    output
    1
    Note

    In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.

    In the second example he can't make a single team.

    In the third example the coach can form three teams. For example, he can do this in the following way:

    • The first group (of two people) and the seventh group (of one person),
    • The second group (of two people) and the sixth group (of one person),
    • The third group (of two people) and the fourth group (of one person).
    • 题意:最多能分多少组,小组有三个人,1+2型,1+1+1型
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int n=5;
     4 int a[n];
     5 int main(){
     6     ios::sync_with_stdio(0);
     7     memset(a,0,sizeof(a));
     8     int n;
     9     cin>>n;
    10     for(int i=0;i<n;i++){
    11         int x;
    12         cin>>x;
    13         a[x]++;
    14     }
    15     if(a[1]==a[2]){
    16         cout<<a[1]<<endl;
    17         return 0;
    18     }else{
    19         int ans=min(a[1],a[2]);
    20         a[1]-=ans;
    21         ans+=a[1]/3;
    22         cout<<ans<<endl;
    23         return 0;
    24     }
    25 }
    B. Months and Years
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.

    A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.

    In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

    Input

    The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers.

    The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.

    Output

    If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

    You can print each letter in arbitrary case (small or large).

    Examples
    input
    4
    31 31 30 31
    output
    Yes

    input
    2
    30 30
    output
    No

    input
    5
    29 31 30 31 30
    output
    Yes

    input
    3
    31 28 30
    output
    No

    input
    3
    31 31 28
    output
    Yes

    Note

    In the first example the integers can denote months July, August, September and October.

    In the second example the answer is no, because there are no two consecutive months each having 30 days.

    In the third example the months are: February (leap year) — March — April – May — June.

    In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.

    In the fifth example the months are: December — January — February (non-leap year).

     模拟吧,多做题找感觉

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn=100;
     4 int n;
     5 int a[maxn];
     6 int k[maxn]={31,28,31,30,31,30,31,31,30,31,30,31,31,
     7     28,31,30,31,30,31,31,30,31,30,31,
     8     31,28,31,30,31,30,31,31,30,31,30,31,
     9     31,29,31,30,31,30,31,31,30,31,30,31,
    10     31,28,31,30,31,30,31,31,30,31,30,31,
    11 31,28,31,30,31,30,31,31,30,31,30,31,};
    12 int main(){
    13     ios::sync_with_stdio(0);
    14     cin>>n;
    15     for(int i=0;i<n;i++){
    16         cin>>a[i];
    17     }
    18     for(int i=0;i<72;i++){
    19         int ans=0;
    20         for(int j=0;j<n;j++){
    21             if(a[j]!=k[i+j]){
    22                 break;
    23             }else{
    24                 ans++;
    25             }
    26         }
    27         if(ans==n){
    28             cout<<"Yes"<<endl;
    29             return 0;
    30         }
    31     }
    32         cout<<"NO"<<endl;
    33     return 0;
    34 }
    C. Dividing the numbers
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.

    Help Petya to split the integers. Each of n integers should be exactly in one group.

    Input

    The first line contains a single integer n (2 ≤ n ≤ 60 000) — the number of integers Petya has.

    Output

    Print the smallest possible absolute difference in the first line.

    In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.

    Examples
    input
    4
    output
    0
    2 1 4
    input
    2
    output
    1
    1 1
    Note

    In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.

    In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.

     找规律吧

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 int main(){
     6     int n;
     7     while(~scanf("%d",&n)){
     8         int k=n%4;
     9         int t=n/4;
    10         if(k==0){
    11             cout<<0<<endl;
    12             cout<<t*2;
    13             for(int i=1;i<=t;i++)
    14                 cout<<" "<<i<<" "<<n-i+1;
    15             cout<<endl;
    16         }
    17         else if(k==1){
    18             cout<<1<<endl;
    19             cout<<t*2+1<<" "<<1;
    20             for(int i=1;i<=t;i++)
    21                 cout<<" "<<i+1<<" "<<n-i+1;
    22             cout<<endl;
    23         }
    24         else if(k==2){
    25             cout<<1<<endl;
    26             cout<<t*2+1<<" "<<1;
    27             for(int i=1;i<=t;i++)
    28                 cout<<" "<<i+2<<" "<<n-i+1;
    29             cout<<endl;
    30         }
    31         else{
    32             cout<<0<<endl;
    33             cout<<t*2+1<<" "<<3;
    34             for(int i=1;i<=t;i++)
    35                 cout<<" "<<i+3<<" "<<n-i+1;
    36             cout<<endl;
    37         }
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    数组
    分支.顺序结构
    博客作业-查找
    DS博客作业-图
    DS 数据结构-树
    数据结构-栈,队列
    博客作业05-指针
    C语言博客作业04-数组
    C语言博客作业03——函数
    c语言博客作业02-循环结构
  • 原文地址:https://www.cnblogs.com/z-712/p/8059142.html
Copyright © 2011-2022 走看看