自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(37)
  • 收藏
  • 关注

原创 Educational Codeforces Round 108 (Rated for Div. 2) D. Maximum Sum of Products

传送门You are given two integer arrays a and b of length n.You can reverse at most one subarray (continuous subsegment) of the array a.Your task is to reverse such a subarray that the sum ∑i=1nai⋅bi is maximized.InputThe first line contains one integer n

2021-04-30 23:53:44 51 1

原创 道路重建

传送门思路:将未被毁坏的道路长度设置为0;#include<bits/stdc++.h>using namespace std;#define ll long long int g[1010][1010];int ma[1010][1010];const int inf = 0x3f3f3f3f;int n,m;int dis[1010];bool vis[1010];void dij(){ for(int k = 1; k <= n; k++) { f

2021-04-30 23:44:26 111 1

原创 Educational Codeforces Round 108 (Rated for Div. 2) B. The Cake Is a Lie

传送门题读错了,我是傻逼。#include<bits/stdc++.h>using namespace std;#define ll long longint main(){ int t; cin>>t; while(t--) { int n,m,k; cin>>n>>m>>k; if(n*m-1 == k) printf("yes\n"); else printf("no\n"); }}..

2021-04-30 11:59:55 98

原创 Educational Codeforces Round 108 (Rated for Div. 2) A. Red and Blue Beans

传送门You have r red and b blue beans. You’d like to distribute them among several (maybe, one) packets in such a way that each packet:has at least one red bean (or the number of red beans ri≥1);has at least one blue bean (or the number of blue beans bi≥1)

2021-04-30 11:58:19 68

原创 NASA的食物计划

传送门思路:dp(a,b)表示v体积m质量食物所能有的最大卡路里。#include<bits/stdc++.h>using namespace std;int vi[410];int mi[410];int w[410];int dp[410][410];int main(){ int v,m; cin>>v>>m; int n; cin>>n; for(int i = 1; i <= n; i++) { cin&g

2021-04-28 23:37:06 91

原创 好奇怪的游戏

传送门#include<bits/stdc++.h>using namespace std;int a[12]={1,1,2,2,2,2,-1,-1,-2,-2,-2,-2};int b[12]={-2,2,-2,-1,1,2,-2,2,-1,1,-2,2};struct node{ int x,y,step;};queue<node>q;int vis[50][50];int bfs(int x1,int y1,int ans){ while(!q.emp

2021-04-28 23:29:24 93

原创 阶乘

N 的阶乘(记作 N!)是指从 1 到 N(包括 1 和 N)的所有整数的乘积。阶乘运算的结果往往都非常的大。现在,给定数字 N,请你求出 N! 的最右边的非零数字是多少。例如 5!=1×2×3×4×5=120,所以 5! 的最右边的非零数字是 2。输入格式共一行,包含一个整数 N。输出格式输出一个整数,表示 N! 的最右边的非零数字。#include<stdio.h>#include<algorithm>using namespace std;const in

2021-04-27 23:55:14 887

原创 亲戚

传送门#include<bits/stdc++.h>using namespace std;int f[5010];int find(int x){ if(f[x]!=x) return f[x] = find(f[x]); return x;}int main(){ int n,m,p; cin>>n>>m>>p; for(int i = 1; i <= n; i++) f[i] = i; while(m--) {

2021-04-27 23:16:03 75

原创 选学霸

传送门思路:需要先用并查集找出每一个需要选择的不同的学霸堆,然后就是01背包的板子题。#include<bits/stdc++.h>using namespace std;const int mod = 1000007;int f[40010];int ans[40010];int vis[40010];int dp[40010];int find(int x){ if(f[x] != x) return f[x] = find(f[x]); return x;

2021-04-26 23:45:02 89

原创 数组去重

给定一个长度为 n 的数组 a,请你编写一个函数:int get_unique_count(int a[], int n); // 返回数组前n个数中的不同数的个数输入格式第一行包含一个整数 n。第二行包含 n 个整数,表示数组 a。输出格式共一行,包含一个整数表示数组中不同数的个数。数据范围1≤n≤1000输入样例:51 1 2 4 5#include<bits/stdc++.h>using namespace std;int a[1010];int main

2021-04-26 23:42:10 341

原创 A-B

传送门本题要求你计算A−B。不过麻烦的是,A和B都是字符串 —— 即从字符串A中把字符串B所包含的字符全删掉,剩下的字符组成的就是字符串A−B。输入格式:输入在2行中先后给出字符串A和B。两字符串的长度都不超过10​4​​ ,并且保证每个字符串都是由可见的ASCII码和空白字符组成,最后以换行符结束。输出格式:在一行中打印出A−B的结果字符串。#include<bits/stdc++.h>using namespace std;const int inf = 0x3f3f3f

2021-04-21 23:51:06 46

原创 Codeforces Round #717 (Div. 2) A. Tit for Tat

传送门Given an array a of length n, you can do at most k operations of the following type on it:choose 2 different elements in the array, add 1 to the first, and subtract 1 from the second. However, all the elements of a have to remain non-negative after th

2021-04-21 23:49:56 120

原创 Codeforces Round #716 (Div. 2) C. Product 1 Modulo N

传送门Now you get Baby Ehab’s first words: “Given an integer n, find the longest subsequence of [1,2,…,n−1] whose product is 1 modulo n.” Please solve the problem.A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (poss

2021-04-20 20:35:51 152

原创 Codeforces Round #716 (Div. 2) A-Perfectly Imperfect Array

Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square.A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements.I

2021-04-19 23:58:53 130

原创 Codeforces Round #716(Div. 2) B - AND 0, Sum Big

Baby Badawy’s first words were “AND 0 SUM BIG”, so he decided to solve the following problem. Given two integers n and k, count the number of arrays of length n such that:all its elements are integers between 0 and 2k−1 (inclusive);the bitwise AND of all

2021-04-19 23:56:14 370

原创 Codeforces Round #715 (Div. 2) C-The Sports Festival

传送门The student council is preparing for the relay race at the sports festival.The council consists of n members. They will run one after the other in the race, the speed of member i is si. The discrepancy di of the i-th stage is the difference between th

2021-04-17 21:58:31 147

原创 Codeforces Round #715 (Div. 2)B. TMT Document

传送门The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it.However, one day, the members somehow entered the sequence into the document at the same time, cre

2021-04-17 01:07:18 227

原创 Educational Codeforces Round 107 (Rated for Div. 2) C. Yet Another Card Deck

You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card — index n. Each card has its color: the i-th card has color ai.You should process q queries. The j-th query is described by integer tj. For each q

2021-04-17 01:00:47 103

原创 合唱队形

传送门思路:从左到右求出1到i的最长上升子序列的长度,再求出1到n的最长下降子序列,最后枚举要求中的最大值。#include<bits/stdc++.h>#define ll long longusing namespace std;int a[110];int dp[110];int dp2[110];int dp3[110];int main(){ int n; cin>>n; for(int i = 1; i <= n; i++) {

2021-04-15 21:10:58 69

原创 股票买卖 II

传送门给定一个长度为 N 的数组,数组中的第 i 个数字表示一个给定股票在第 i 天的价格。设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。输入格式第一行包含整数 N,表示数组长度。第二行包含 N 个不大于 10000 的正整数,表示完整的数组。输出格式输出一个整数,表示最大利润。数据范围1≤N≤1e5思路:当前状态分为两种,买或不买,若不买,则根据上次情况:上次买,则这次

2021-04-15 20:29:43 64

原创 Array Shrinking

传送门You are given an array a1,a2,…,an. You can perform the following operation any number of times:Choose a pair of two neighboring equal elements ai=ai+1 (if there is at least one such pair).Replace them by one element with value ai+1.After each such o

2021-04-14 21:54:04 156

原创 P3146 [USACO16OPEN]248 G

思路:枚举区间长度,起点,分割点。#include<bits/stdc++.h>using namespace std;int a[300];int dp[300][300];int main(){ int n; cin>>n; for(int i = 1; i <= n; i++) { cin>>a[i]; dp[i][i] = a[i]; } int ans = 0; for(int len = 1; len <= .

2021-04-13 20:52:47 43

原创 Boredom

Alex doesn’t like boredom. That’s why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single step he

2021-04-13 00:27:06 101

原创 石子合并

传送门将 n 堆石子绕圆形操场排放,现要将石子有序地合并成一堆。规定每次只能选相邻的两堆合并成新的一堆,并将新的一堆的石子数记做该次合并的得分。请编写一个程序,读入堆数 n 及每堆的石子数,并进行如下计算:选择一种合并石子的方案,使得做 n−1 次合并得分总和最大。选择一种合并石子的方案,使得做 n−1 次合并得分总和最小。输入格式输入第一行一个整数 n,表示有 n 堆石子。第二行 n 个整数,表示每堆石子的数量。输出格式输出共两行:第一行为合并得分总和最小值,第二行为合并得分总和最大

2021-04-12 23:36:23 428

原创 Codeforces Round #713 (Div. 3) A-B Palindrome

传送门 C. A-B PalindromeYou are given a string s consisting of the characters ‘0’, ‘1’, and ‘?’. You need to replace all the characters with ‘?’ in the string s by ‘0’ or ‘1’ so that the string becomes a palindrome and has exactly a characters ‘0’

2021-04-11 21:38:33 237

原创 子序列个数

传送门子序列的定义:对于一个序列a=a1,a2,…an。则非空序列a’=ap1,ap2…apm为a的一个子序列,其中1<=p1<p2<…<pm<=n。例如4,14,2,3和14,1,2,3都为4,13,14,1,2,3的子序列。对于给出序列a,有些子序列可能是相同的,这里只算做1个,请输出a的不同子序列的数量。由于答案比较大,输出Mod 10^9 + 7的结果即可。Input第1行:一个数N,表示序列的长度(1 <= N <= 100000) 第2 - N

2021-04-11 21:35:39 260

原创 Basketball Exercise

传送门Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2⋅n students have come to Demid’s exercise session, and he lined up them into two rows of the same size (there are exactly n people in each

2021-04-10 17:24:57 162

原创 编辑距离

传送门编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数。许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。例如将kitten一字转成sitting:sitten (k->s)sittin (e->i)sitting (->g)所以kitten和sitting的编辑距离是3。俄罗斯科学家Vladimir Levenshtein在1965年提出这个概念。给出两个字符串a,

2021-04-10 17:18:51 181

原创 最长公共子序列Lcs

传送门给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的)。比如两个串为:abcicbaabdkscabab是两个串的子序列,abc也是,abca也是,其中abca是这两个字符串最长的子序列。Input第1行:字符串A 第2行:字符串B (A,B的长度 <= 1000)Output输出最长的子序列,如果有多个,随意输出1个。思路:设 dp[i][j] 为a串前i个与b串前j个串里的最长公共子序列。以O(mn)遍历a,b串,若a[i] == b[j],则dp[i

2021-04-09 21:22:45 113

原创 最长递增子序列

传送门给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。Input第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= Si <= 10^9)Output输出最长递增子序列的长度。思路:以O(n)来遍历序列,dp[i]储存当前最优子序列,每当遇到a[j] > dp

2021-04-09 19:09:24 70

原创 最大连续子段和

传送门给定有n个整数(可能为负整数)组成的序列a1,a2,…,an,求该序列连续的子段和的最大值。如果该序列的所有元素都是负整数时定义其最大子段和为0。例如,当(a1,a2,a3,a4,a5)=(-5,11,-4,13,-4-2)时,最大子段和为11+(-4)+13=20。Input第一行整数个数N 第二行为N个整数,每个整数之间用一空格隔开。 1<=N<=100000 N个整数的范围为-1000到1000Output一行一个数,表示最大连续子段和的值思路:判断当前所选的a[i]

2021-04-08 19:07:50 1036

原创 你猜这是什么题

传送门题目描述一段来自神奇天书的文字由n个小写英文字母组成。经过多年传承,这里面藏有许多的暗语,只有解出来,你才能看到真正的文字。看到它使你快乐,不可能的!已知,共有m名大师参与修订。到第ii名大师之手后,他立即同其他人一样做出了如下修改:他采用了天书的最新版本,并用xx替代所有的y,y替代x,这样就产生了新版本。这些字母中的某些字母可能不会出现在字符串中。 x也可能与y一致。最后一位大师工作替换后的天书即为最新版本。你迫不及待的想要看懂天书,以助你得到质的飞跃,但是你只有最初版本的天书以及替换过程

2021-04-08 18:57:54 56

原创 序列拆分

传送门题目描述给出一个含有nn个数的整数序列,把它拆分成两个序列,使分成的两个序列之和的差值最小输入格式第一行一个正整数n,第二行含n个正整数的序列a[n]。输出格式一个正整数表示分成的两个子序列之和的最小差值思路:先得出序列的总值sum,然后用01背包解法找到小于等于sum/2的子序列。#include<bits/stdc++.h>using namespace std;#define ll long longint a[110];int dp[1100000];

2021-04-07 22:53:41 810

原创 FATE

传送门最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务。久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级。现在的问题是,xhd升掉最后一级还需n的经验值,xhd还留有m的忍耐度,每杀一个怪xhd会得到相应的经验,并减掉相应的忍耐度。当忍耐度降到0或者0以下时,xhd就不会玩这游戏。xhd还说了他最多只杀s只怪。请问他能升掉这最后一级吗?Input输入数据有多组,对于每组数据第一行输入n,m,k,s(0 < n,m,k,s < 100

2021-04-06 21:13:34 157

原创 Robberies

传送门The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, be

2021-04-03 19:47:50 123

原创 P1060 [NOIP2006 普及组] 开心的金明

传送门#include<bits/stdc++.h>using namespace std;#define ll long longint v[30];int p[30];int dp[30010];int main(){ int n,m; cin>>n>>m; for(int i = 1; i <= m; i++) cin>>v[i]>>p[i]; for(int i = 1; i <= m; i++)

2021-04-02 19:26:28 161

原创 Buns

传送门Lavrenty, a baker, is going to make several buns with stuffings and sell them.Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-th stuff

2021-04-02 11:58:32 263

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除