zoukankan      html  css  js  c++  java
  • Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers

    题目链接:http://codeforces.com/contest/872/problem/A

    题目意思:题目很简单,找到一个数,组成这个数的数字即在A数组中出现过,也在B数组中出现过,问这个数最小是多少。

    题目思路:首先要么一个数两个数组都出现过直接输出来,要么分别取两个数组中最小的数组合一下输出。

    代码:

     1 //Author: xiaowuga
     2 #include <bits/stdc++.h>
     3 using namespace std;
     4 #define inf 0x3f3f3f3f
     5 #define MAX INT_MAX
     6 #define mem(s,ch) memset(s,ch,sizeof(s))
     7 const long long N=100000; 
     8 const long long mod=1e9+7; 
     9 typedef long long LL;
    10 typedef int II;
    11 typedef unsigned long long ull;
    12 #define nc cout<<"nc"<<endl
    13 #define endl "
    "
    14 int main() {
    15     ios::sync_with_stdio(false);cin.tie(0);
    16     int a=20,b=20;
    17     int n,m;
    18     int aa[10]={0},bb[10]={0};
    19     cin>>n>>m; 
    20     for(int i=0;i<n;i++){
    21         int t;
    22         cin>>t;
    23         a=min(a,t);
    24         aa[t]=1;
    25     } 
    26     for(int i=0;i<m;i++){
    27         int t;
    28         cin>>t;
    29         b=min(b,t);
    30         bb[t]=1;
    31     } 
    32     for(int i=1;i<=9;i++){
    33         if(aa[i]&&bb[i]){
    34             cout<<i<<endl;
    35             return 0;
    36         }
    37     } 
    38     if(a>b) swap(a,b);
    39     cout<<(a*10)+b<<endl;
    40     return 0;
    41 }
    View Code

    B. Maximum of Maximums of Minimums

    题目链接:http://codeforces.com/contest/872/problem/B

    题目意思:一个数列有n个数,现在把他分成k份,要让k份中每一份中的最小值的最大值最大。

    题目思路:当k=1的时候,答案必定是数列的最小值,当k>2的时候,答案必定是数列的最大值。当k=2的时候但是必定是数列第一项和最后一项中最大值。

    代码:

     1 //Author: xiaowuga
     2 #include <bits/stdc++.h>
     3 using namespace std;
     4 #define inf 0x3f3f3f3f
     5 #define MAX INT_MAX
     6 #define mem(s,ch) memset(s,ch,sizeof(s))
     7 const long long N=100000; 
     8 const long long mod=1e9+7; 
     9 typedef long long LL;
    10 typedef int II;
    11 typedef unsigned long long ull;
    12 #define nc cout<<"nc"<<endl
    13 #define endl "
    "
    14 int main() {
    15     ios::sync_with_stdio(false);cin.tie(0);
    16     long long a[100000+10];
    17     int n,k;
    18     cin>>n>>k;
    19     long long mi=inf,ma=-inf;
    20     for(int i=0;i<n;i++){
    21         cin>>a[i];
    22         mi=min(mi,a[i]);
    23         ma=max(ma,a[i]);
    24     }
    25     if(k==1) cout<<mi<<endl;
    26     else if(k>2) cout<<ma<<endl;
    27     else {
    28         cout<<max(a[0],a[n-1])<<endl;
    29     }
    30     return 0;
    31 }
    View Code

    C. Maximum splitting

    题目链接:http://codeforces.com/contest/872/problem/C

    题目意思:给出一个数,可以分成多少个合数的和。
    题目思路:首先最小的合数是4,所以根据贪心的思路就是尽量分出4来。直接代码吧

    代码:

     1 //Author: xiaowuga
     2 #include <bits/stdc++.h>
     3 using namespace std;
     4 #define inf 0x3f3f3f3f
     5 #define MAX INT_MAX
     6 #define mem(s,ch) memset(s,ch,sizeof(s))
     7 const long long N=100000; 
     8 const long long mod=1e9+7; 
     9 typedef long long LL;
    10 typedef int II;
    11 typedef unsigned long long ull;
    12 #define nc cout<<"nc"<<endl
    13 #define endl "
    "
    14 int main() {
    15     ios::sync_with_stdio(false);cin.tie(0);
    16     int q;
    17     long long k;
    18     cin>>q;
    19     while(q--){
    20        cin>>k; 
    21        long long x=k/4;
    22        if(k%4==0) cout<<x<<endl;
    23        else if(k%4==1){
    24            if(x-2>=0){
    25                cout<<x-1<<endl;
    26            }
    27            else cout<<-1<<endl;
    28        }
    29        else if(k%4==2){
    30            if(x-1>=0){
    31                cout<<x<<endl;
    32            }
    33            else cout<<-1<<endl;
    34        }
    35        else if(k%4==3){
    36            if(x-3>=0){
    37                cout<<x-1<<endl;
    38            } 
    39            else cout<<-1<<endl;
    40        } 
    41     }
    42     return 0;
    43 }
    View Code
  • 相关阅读:
    CodeForces 706C Hard problem
    CodeForces 706A Beru-taxi
    CodeForces 706B Interesting drink
    CodeForces 706E Working routine
    CodeForces 706D Vasiliy's Multiset
    CodeForces 703B Mishka and trip
    CodeForces 703C Chris and Road
    POJ 1835 宇航员
    HDU 4907 Task schedule
    HDU 4911 Inversion
  • 原文地址:https://www.cnblogs.com/xiaowuga/p/7693689.html
Copyright © 2011-2022 走看看