Codeforces Global Round 3
同样还是补题 老年人晚上熬不起夜(其实是那天去找女朋友玩了回来晚了 A. Another One Bites The Dust 题意 给出a个"a" b个"b" c个"ab" 然后能组成如"ababa"形串的最大长度 水题 如果a == b的话 就刚好按若干个ab的顺序排 即最长长度为(a + c) * 2 a != b的话 也是按若干个ab排 但多出来的一个a可以排在最后一个b后面 同理 多出来的一个b可以排在最先一个a前面 即最长长度(min(a,b) + c) * 2 + 1 AC代码: 1 #include<bits/stdc++.h> 2 #define pi acos(-1) 3 typedef long long ll; 4 typedef unsigned long long ull; 5 using namespace std; 6 7 namespace io { 8 const int SIZE = 1e7 + 10; 9 char inbuff[SIZE]; 10 char *l,*r; 11 inline void init() { 12 l = inbuff; 13 r = inbuff + fread(inbuff,1,SIZE,stdin); 14 } 15 inline char gc() { 16 if (l == r) init(); 17 return (l != r) ? *(l++) : EOF; 18 } 19 void read(int &x) { 20 x = 0; char ch = gc(); 21 while(!isdigit(ch)) ch = gc(); 22 while(isdigit(ch)) x = x * 10 + ch - ‘0‘,ch = gc(); 23 } 24 } using io::read; 25 26 bool cmp(const int &a,const int &b){ 27 return a > b; 28 } 29 30 int main(){ 31 ll a,b,c; 32 cin>>a>>b>>c; 33 if (a == b) cout<<(a + c) * 2<<endl; 34 else cout<<(min(a,b) + c) * 2 + 1<<endl; 35 return 0; 36 } ? B. Born This Way 题意 某个人要买张从A到C的机票 但是上帝并不想让他这么顺利(瞎编的) 他只能从A飞到B 再从B飞到C 给出n趟从A到B的飞机起飞时刻与m趟从B到C的飞机起飞时刻还有A到B的飞机飞行时间ta和B到C的飞机飞行时间tb 你现在要千方百计让这个人最晚时间到达目的地 你能取消小于等于k趟航班 若取消后不能到达 输出-1 否则 输出最晚的时间 先直接把a数组都加上ta 再跟b数组的每一项比较 注意特判n <= k或m <= k时的情况 AC代码: 1 #include<bits/stdc++.h> 2 #define pi acos(-1) 3 typedef long long ll; 4 typedef unsigned long long ull; 5 using namespace std; 6 7 namespace io { 8 const int SIZE = 1e7 + 10; 9 char inbuff[SIZE]; 10 char *l,const int &b){ 27 return a > b; 28 } 29 30 const int N = 2e5 + 5; 31 ll n,m,ta,tb,k; 32 ll a[N],b[N]; 33 ll ans; 34 35 int main(){ 36 cin>>n>>m>>ta>>tb>>k; 37 bool flag = true; 38 for (int i = 1; i <= n; i++){ 39 cin>>a[i]; 40 a[i] += ta; 41 } 42 for (int i = 1; i <= m; i++) cin>>b[i]; 43 for (int i = 0; i <= k; i++){ 44 int t = lower_bound(b + 1,b + 1 + m,a[i + 1]) - b + k - i; 45 if (t > m){ 46 flag = false; 47 break; 48 } 49 ans = max(ans,b[t] + tb); 50 } 51 if (n <= k || m <= k) flag = false; 52 if (flag) cout<<ans<<endl; 53 else cout<<-1<<endl; 54 return 0; 55 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |