CF851 D 枚举 思维】的更多相关文章

给出n个数,你可以对每个数把它变为0,或者增加1,分别需要花费x, y.问把所有数的GCD变为不为1的最小花费是多少. n的范围5x1e5,a[i]的范围1e6. 开始想通过枚举最终gcd值,然后通过判左右个数以及消费来二分,显然是愚蠢的想法,因为一个数在不同模数下余数并不单调阿! 实际上是枚举gcd值,首先a[i]只有1e6范围,预处理前缀和:cnt[i]表示前a[] < i的个数和,sum[i] 比i小的所有a[]的和. 这样在枚举gcd的倍数值时,只要找到gcd范围内的一个划分,小于该划分…
方法一:因为最多是10的六次方,所以可以直接枚举二进制上的每一位来得到最优结果. AC代码: #include<iostream> #include<stack> #include<stdio.h> #include<queue> #include<map> #include<algorithm> #include<vector> #include<string> #include<cmath> #…
题意:有N个主武器(MW)和M个副武器(SW),每个武器都有自己的S值,和K个附加属性xi.要选取一对主副武器搭配,搭配后获得的性能由该公式得出: 求获得最大的性能为多少. 分析:由于|xm - xs| = max (xm - xs, xs -xm) .所以每种武器如果选择,则其属性xi在最后贡献中只有正负两种状态.那么对于每一种武器,其对最终贡献可能有2^K中组合, 若主武器的一种组合为S,则其选取的副武器的组合即为S的补集.所以对每一种组合S,枚举每个武器在该组合下的贡献并记录最大值. 最后…
Salem gave you nn sticks with integer positive lengths a1,a2,-,ana1,a2,-,an. For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from aa to bb…
2019 杭电多校 9 1006 题目链接:HDU 6685 比赛链接:2019 Multi-University Training Contest 9 Problem Description Rikka hates coins, and she used to never carry any coins with her. These days, Rikka is doing her summer internship abroad. Without mobile payment, Rikka…
CodeForces-38B-Chess 这是一道与下象棋有关的题目,题意是给你一个车和马的坐标,然后再给你一个马,让你判断最后三者都不会被吃掉的可能性,注意的是三者是三个独立的个体. 这道题要知道一点下象棋的规则:马走“日”字, 车可以直线随便走,然后判断车和马的八个方向和车的行和列即可. 这里有个技巧,马的八个方向可以用两点距离为5的根号判断:注意rook是车,knight是马 #include <cstdio> #include <iostream> #include <…
Code: #include <bits/stdc++.h> #define ll long long #define setIO(s) freopen(s".in","r",stdin) #define maxn 3002 using namespace std; queue<int>Q; vector<int>G[maxn]; int n,m,s1,t1,l1,s2,t2,l2; int vis[maxn],d[maxn][m…
Online Judge:Luogu,Codeforces Round #592 (Div. 2) C Label:数学,思维题, 枚举 题目描述 某球队一共打了\(n\)场比赛,总得分为\(p\),已知赢一场得\(w\)分,平局一场得\(d\)分,输一场不加分也不减分,问一共赢了几场(x),平局了几场(y),输了几场(z)?如果不存在合法方案输出"-1",如果存在多组可能的方案,任意输出一组(Special Judge). 也就是任求一组符合条件的非负整数三元组\((x,y,z)\)…
Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10931   Accepted: 4029 Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in whic…
Problem A: An easy problem Description Peter Manson owned a small house in an obscure street. It was a weather-beaten tenement of wood, containing some six or eight rooms, all of which, with one exception, were given over to dirt, cobwebs, gloom, and…
心得: 这比赛真的是不要不要的,pending了一下午,也不知道对错,直接做过去就是了,也没有管太多! Problem A: 两只老虎 Description 来,我们先来放松下,听听儿歌,一起“唱”. 两只老虎两只老虎,跑得快跑得快. 一只没有耳朵,一只没有尾巴. 真奇怪,真奇怪. Tmk也觉得很奇怪,因为在他面前突然出现了一群这样的老虎,有的没耳朵,有的没尾巴,不过也有正常的. 现在Tmk告诉你这群老虎的耳朵个数,尾巴条数,以及老虎的腿的数目,问你有多少只是正常的. 其中只有三种老虎: 第一…
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which…
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3791  Solved: 2234[Submit][Status][Discuss] Description 相信大家都玩过扫雷的游戏.那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了 ,“余”人国流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子没有雷,那么它里面的数字 表示和它8连通的格子里面雷的数目.现在棋盘是…
给你n个数,问有几个区间满足,区间内或操作大于区间内的任意数. 首先可以知道,两数或操作的结果必定不会小于两者间的最大值,也就是说对于一个区间中,不合法的状态只有两值或相等.那么我们可以考虑枚举每个数,向左向右找到第一个或不相等的,那么该数对所有不合法区间的贡献就能找到了,所以与其找合法的区间不如容斥找不合法的区间. 具体从左往右枚举每个数,同时记录该数某二进制位为0时,左侧数中该位出现1的离i的最近位置,得到左边界.右边界类似. 然后就是要注意重复的数,重复的数出现直接就使区间不合法,左右两侧…
题目链接 这道题意思是: 给你一个长度为9的字符串,且只有3个a.3个g.3个o 问,你可以选择删除一段连续的串或者单个的字符也可以不删,最多会出现几个三子相连的子串 比如:agoagoago只有将两种删除完,才能得到三子相连,所以是1 aaoogggoa,首先里面有一个三子相连(ggg),然后我们删除ggg这三个连续的字符,之后会出现ooo,删除ooo,之后会出现aaa,所以答案是3 我们可以分析到: 先检测原串中有几个三子相连,且只会得到0个,1个或者3个,不会有2个 如果原串有一个三子相连…
#include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char b[507];int dp[507][507];int main(){    memset(dp,0x3f,sizeof(dp));    int n;    scanf("%d",&n);    scanf("%s",b+1);    for(int i=1;…
Given a string ss of length nn and integer kk (1≤k≤n1≤k≤n). The string ss has a level xx, if xx is largest non-negative integer, such that it's possible to find in ss: xx non-intersecting (non-overlapping) substrings of length kk, all characters of t…
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just de…
C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily the bear has got a sequence of positive integers a1, a2, ..., *a**n*. Vasily the Bear wants to write o…
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the size of the input. You are given a string s consistin…
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers…
题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1]需要是辅音字母,且s[i]和s[i-1]中需要一个字母大写另一个小写.a.e.i.o.u.w.y这七个字母是元音 输出最大字符对数量 题解1: 首先预处理一下s字符串中字符相邻的数量,就是记录w[s[i-1]][s[i]]的数量 之后二进制枚举所有字母变成大写的情况. 然后枚举这个字母变成大写之后…
P1876 开灯 题目背景 该题的题目是不是感到很眼熟呢? 事实上,如果你懂的方法,该题的代码简直不能再短. 但是如果你不懂得呢?那...(自己去想) 题目描述 首先所有的灯都是关的(注意是关!),编号为1的人走过来,把是一的倍数的灯全部打开,编号为二的的把是二的倍数的灯全部关上,编号为3的人又把是三的倍数的灯开的关上,关的开起来……直到第N个人为止. 给定N,求N轮之后,还有哪几盏是开着的. 输入输出格式 输入格式: 一个数N,表示灯的个数和操作的轮数 输出格式: 若干数,表示开着的电灯编号…
题意 题目链接 Sol 好好读题 => 送分题 不好好读题 => 送命题 开始想了\(30\)min数据结构发现根本不会做,重新读了一遍题发现是个傻逼题... \(C_{i, j} = a[i] * b[j]\) 根据乘法分配律,题目就变成了在数组\(a, b\)中分别选一段连续的区间,要求权值和相乘\(<= X\),最大化区间长度乘积 \(n^2\)模拟一下即可 #include<bits/stdc++.h> #define Pair pair<int, int>…
Problem Description A cubic number is the result of using a whole number in a multiplication three times. For example, 3×3×3=27 so 27 is a cubic number. The first few cubic numbers are 1,8,27,64 and 125 . Given an prime number p . Check that if p is…
Kali Linux是一个全面的渗透测试平台,其自带的高级工具可以用来识别.检测和利用目标网络中未被发现的漏洞.借助于Kali Linux,你可以根据已定义的业务目标和预定的测试计划,应用合适的测试方法论,从而达到预期的渗透测试结果.本书采用循序渐进的方法讲解了前沿的黑客工具和技术,有助于提高读者的渗透测试实用技巧.本书提供了所有必需的实验准备和测试流程,旨在从业务的角度反映真实世界中的攻击场景.   本书内容:通过安装.配置.运行和升级核心系统组件来设置Kali Linux的测试环境:执行正规…
[吐槽]:本来没打算写这题的题解的,但惨不忍睹得WA了13次,想想还是记录一下吧.自己的“分类讨论能力”本来就很差. 刚开始第一眼扫过去以为是LIS,然后忽略了复杂度,果断TLE了,说起来也好惭愧,也说明有时候太懒得动脑了,总是习惯利用惯性思维,这不是一件好事. [题意]:给你大小为n的整型数组a[n],求这数组的一个子串,其中最多可以修改子串中的一个数字,使得到的子串是最长的严格递增的子串,输出该子串的长度 L. [思路]:O(n)复杂度,枚举断点情况.第0个和第n个位置默认为断点.(用ve[…