BestCoder Round #47 (ABC)

2024-03-20 14:08
文章标签 round 47 bestcoder abc

本文主要是介绍BestCoder Round #47 (ABC),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

比赛链接:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=608

Senior's Array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 888    Accepted Submission(s): 324

Problem Description
One day, Xuejiejie gets an array A . Among all non-empty intervals of A , she wants to find the most beautiful one. She defines the beauty as the sum of the interval. The beauty of the interval--- [L,R] is calculated by this formula : beauty(L,R) = A[L]+A[L+1]++A[R] . The most beautiful interval is the one with maximum beauty.
But as is known to all, Xuejiejie is used to pursuing perfection. She wants to get a more beautiful interval. So she asks Mini-Sun for help. Mini-Sun is a magician, but he is busy reviewing calculus. So he tells Xuejiejie that he can just help her change one value of the element of A to P . Xuejiejie plans to come to see him in tomorrow morning.
Unluckily, Xuejiejie oversleeps. Now up to you to help her make the decision which one should be changed(You must change one element).
 
Input
In the first line there is an integer T , indicates the number of test cases.
In each case, the first line contains two integers n and P . n means the number of elements of the array. P means the value Mini-Sun can change to.
The next line contains the original array.
1n1000 , 109A[i],P109
 
Output
For each test case, output one integer which means the most beautiful interval's beauty after your change.
 
Sample Input
  
2 3 5 1 -1 2 3 -2 1 -1 2
 
Sample Output
  
8 2
 
题目大意:给一组数和一个数,要求用这个数字更换数组中的某个数值必须且仅一次,问更换后的最大连续和

题目分析:数据不大,O(n^2)直接搞,枚举更换位置

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
int const MAX = 1005;
ll const INF = 1e16;
ll a[MAX];int main()
{int T;scanf("%d", &T);while(T--){int n, p;scanf("%d %d", &n, &p);for(int i = 1; i <= n; i++)scanf("%I64d", &a[i]);ll ans = -INF;for(int i = 1; i <= n; i++){ll t = a[i];a[i] = p;ll cur = 0, ma = -INF;for(int j = 1; j <= n; j++){cur += a[j];if(cur > ma)ma = cur;if(cur < 0)cur = 0;}a[i] = t;ans = max(ans, ma);}printf("%I64d\n", ans);}
}


Senior's Gun

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 859    Accepted Submission(s): 313


Problem Description
Xuejiejie is a beautiful and charming sharpshooter.
She often carries n guns, and every gun has an attack power a[i] .
One day, Xuejiejie goes outside and comes across m monsters, and every monster has a defensive power b[j] .
Xuejiejie can use the gun i to kill the monster j , which satisfies b[j]a[i] , and then she will get a[i]b[j] bonus .
Remember that every gun can be used to kill at most one monster, and obviously every monster can be killed at most once.
Xuejiejie wants to gain most of the bonus. It's no need for her to kill all monsters.
 

Input
In the first line there is an integer T , indicates the number of test cases.
In each case:
The first line contains two integers n , m .
The second line contains n integers, which means every gun's attack power.
The third line contains m integers, which mean every monster's defensive power.
1n,m100000 , 109a[i],b[j]109
 
Output
For each test case, output one integer which means the maximum of the bonus Xuejiejie could gain.
 
Sample Input
   
1 2 2 2 3 2 2
 

Sample Output
   
1
 
题目大意:n把枪,每把攻击力ai,m个怪,每个怪防御力bi,每把枪只能用一次,每用ai枪杀bi怪可得到ai-bi的利润,求最大利润

题目分析:显然我们要用攻击力最大的几把枪去杀掉防御力最低的几个怪,排个序模拟一下


#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
int const MAX = 1e5 + 5;
int a[MAX], b[MAX];int main()
{int T;scanf("%d", &T);while(T--){int m, n;scanf("%d %d", &n, &m);for(int i = 0; i < n; i++)scanf("%d", &a[i]);for(int i = 0; i < m; i++)scanf("%d", &b[i]);sort(a, a + n);sort(b, b + m);ll ans = 0;int j = n - 1;for(int i = 0; i < min(n, m) && j != -1; i++){if(a[j] > b[i]){ans += a[j] - b[i];j --;}else break;}printf("%I64d\n", ans);}
}


Senior's String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 355    Accepted Submission(s): 133


Problem Description
Xuejiejie loves strings most. In order to win the favor of her, a young man has two strings X , Y to Xuejiejie. Xuejiejie has never seen such beautiful strings! These days, she is very happy. But Xuejiejie is missish so much, in order to cover up her happiness, she asks the young man a question. In face of Xuejiejie, the young man is flustered. So he asks you for help.
The question is that :
Define the L as the length of the longest common subsequence of X and Y .( The subsequence does not need to be continuous
in the string, and a string of length L has 2L subsequences containing the empty string ). Now Xuejiejie comes up with all subsequences of length L of string X , she wants to know the number of subsequences which is also the subsequence of string Y .
 
Input
In the first line there is an integer T , indicates the number of test cases.
In each case:
The first line contains string X , a non-empty string consists of lowercase English letters.
The second line contains string Y , a non-empty string consists of lowercase English letters.
1|X|,|Y|1000 , |X| means the length of X .
 
Output
For each test case, output one integer which means the number of subsequences of length L of X which also is the subsequence of string Y modulo 109+7 .
 
Sample Input
   
2 a b aa ab
 
Sample Output
   
1 2
 
题目大意:给两个字符串x,y,从字符串x中取出所有LCS(x,y)长度的子串,问有多少个也是y的子串

题目分析:很好的一道题,二次dp,第一次求LCS,这个不多说,第二次记cnt[i][j]为到x的i位置和y的j位置时长度为dp[i][j]的公共子串的个数。因为是从x中选,那么就考虑x的第i个字符选不选
如果dp[i][j] == dp[i - 1][j]即长度相等,则不选cnt[i][j] += cnt[i][j - 1]

选的情况下,x的第i个字符必然和y的某个字符相等,那肯定选y中在j之前最后一个与之相等的
dp[i][j] == dp[i - 1][p - 1] + 1
cnt[i][j] += cnt[i - 1][p - 1]


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const MOD = 1e9 + 7;
int const MAX = 1005;
char x[MAX], y[MAX];
int dp[MAX][MAX], cnt[MAX][MAX];int main()
{int T;scanf("%d", &T);while(T--){memset(cnt, 0, sizeof(cnt));scanf("%s %s", x + 1, y + 1);int l1 = strlen(x + 1);int l2 = strlen(y + 1);for(int i = 1; i <= l1; i++)for(int j = 1; j <= l2; j++)dp[i][j] = (x[i] == y[j] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]));cnt[0][0] = 1;for(int i = 1; i <= l1; i++)cnt[i][0] = 1;for(int j = 1; j <= l2; j++)cnt[0][j] = 1;for(int i = 1; i <= l1; i++){int p = 0;for(int j = 1; j <= l2; j++){if(x[i] == y[j])p = j;if(dp[i][j] == dp[i - 1][j])cnt[i][j] = (cnt[i][j] % MOD + cnt[i - 1][j] % MOD) % MOD;if(p && dp[i][j] == dp[i - 1][p - 1] + 1)cnt[i][j] = (cnt[i][j] % MOD + cnt[i - 1][p - 1] % MOD) % MOD;}}printf("%d\n", cnt[l1][l2] % MOD);}
}


这篇关于BestCoder Round #47 (ABC)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/829703

相关文章

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

代码训练营 Day26 | 47.排序II | 51. N-皇后 |

47.排序II 1.跟46题一样只不过加一个树层去重 class Solution(object):def backtracking(self,nums,path,result,used):# recursion stopif len(path) == len(nums):# collect our setresult.append(path[:])return for i in range(

代码随想录刷题day25丨491.递增子序列 ,46.全排列 ,47.全排列 II

代码随想录刷题day25丨491.递增子序列 ,46.全排列 ,47.全排列 II 1.题目 1.1递增子序列 题目链接:491. 非递减子序列 - 力扣(LeetCode) 视频讲解:回溯算法精讲,树层去重与树枝去重 | LeetCode:491.递增子序列_哔哩哔哩_bilibili 文档讲解:https://programmercarl.com/0491.%E9%80%92%E

Codeforces Round 971 (Div. 4) (A~G1)

A、B题太简单,不做解释 C 对于 x y 两个方向,每一个方向至少需要 x / k 向上取整的步数,取最大值。 由于 x 方向先移动,假如 x 方向需要的步数多于 y 方向的步数,那么最后 y 方向的那一步就不需要了,答案减 1 代码 #include <iostream>#include <algorithm>#include <vector>#include <string>

MemSQL Start[c]UP 2.0 - Round 1A(构造)

题目链接:http://codeforces.com/problemset/problem/452/A 解题思路: 打个表暴力查找匹配。 完整代码: #include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#include <strin

Codeforces Round #281 (Div. 2)A(构造+暴力模拟)

题目链接:http://codeforces.com/problemset/problem/493/A 解题思路: 暴力的判断,分三种情况去判断即可。注意如果之前已经被罚下场后,那么在后面的罚下情况不应该算在输出结果内。 完整代码: #include <algorithm>#include <iostream>#include <cstring>#include <co

Codeforces Round #182 (Div. 2)A(水题)

题目链接:http://codeforces.com/contest/302/problem/A 解题思路: 只要通过重新排列使区间内和为0即是1,否则是0. 完整代码: #include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#inc