題目連接:http://codeforces.com/contest/872/problem/Aios
題目意思:題目很簡單,找到一個數,組成這個數的數字即在A數組中出現過,也在B數組中出現過,問這個數最小是多少。c++
題目思路:首先要麼一個數兩個數組都出現過直接輸出來,要麼分別取兩個數組中最小的數組合一下輸出。數組
代碼:ide
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 "\n" 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 }
題目連接:http://codeforces.com/contest/872/problem/Bspa
題目意思:一個數列有n個數,如今把他分紅k份,要讓k份中每一份中的最小值的最大值最大。code
題目思路:當k=1的時候,答案一定是數列的最小值,當k>2的時候,答案一定是數列的最大值。當k=2的時候可是一定是數列第一項和最後一項中最大值。blog
代碼:ci
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 "\n" 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 }
題目連接:http://codeforces.com/contest/872/problem/Cget
題目意思:給出一個數,能夠分紅多少個合數的和。
題目思路:首先最小的合數是4,因此根據貪心的思路就是儘可能分出4來。直接代碼吧it
代碼:
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 "\n" 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 }