Codeforces Round #376 (Div. 2) C D F
在十五楼做的cf..一会一断...比赛的时候做出了ABCF 就没有时间了 之后没看题解写出了D..E是个神奇的博弈(递推或者dp?)看了题解也没有理解..先写了CDF..
C 有n个袜子 每个袜子都有颜色 给出m天穿的两只袜子编号 要求现在进行涂色 保证后m天每天的两只袜子都是一个颜色
可以想到和同一只袜子一起穿过的两只袜子 a == b && c == b 那就a == b 了 这样可以推出有关系的袜子都应该是一个颜色(连通分量)
由于要求出来最小涂多少只 那就bfs求一下连通分量大小 再减去其中最多的颜色 就是这个连通分量中要进行的涂色个数了 需要注意的是 有些袜子不会被穿 那就不管
..比赛的时候写错了一句话 wa了好几次..因为怕重边太多终测超时 加了个map判断又交一次 赛后发现有重边跑的比判重还快...
D 有n个序列 每个序列有len[i]个数字 每次可以进行一次操作 把所有的序列里面的所有的数字都加一 如果增加后等于c+1就变成1
求出进行ans次操作之后 这些序列符合字典序(即将这个序列变成string 满足a[i]<=a[i+1])
n和len都达到了50w c也达到了100w 存是肯定存不下 那就滚动数组来弄 只需要保证经过转动之后每一个序列比前一个大或者等于就可以了
由给出的字典序的定义可以看出 两个字符串的相同前缀不做考虑 只考虑第一个不同的 不同的数字肯定会在操作一定次数之后 关系变成前者小于后者 这时候 可以得出一个区间
最后会得出n-1个区间 求一个次数 在所有的区间中
其实是比较好想的 模拟就是了 但是有个trick是 如果前者大于后者 那么只会得出来一个区间 l是前者为1次数 r是后者为1次数-1
但是如果前者小于后者 就有可能会出现两个区间 但是这两个区间的维度是一样的 这两个在n-1个区间中同属于一个区间
所以不能简单的比较最大的l和最小的r 应该用一个计算当前数字在多少个区间内的方法判断这个数是否可行
F 有n个数的集合 在这n个数中选一个子集(可以直接选这个集合) 在这个子集中选出一个基准数 把其他的数全部变为 基准数*(x/基准数) 然后得出res为这个子集的sum 问res最大是多少
wa着C的时候看见好多人过F..不知所措..于是过了C之后就去看这个了
想了想 把这n个数去重sort之后 当我们选择a[i]之后 可以往后面卡出z个区间a[i] - 2*a[i]-1,2*a[i] - 3*a[i]-1,....一直到k*a[i] - (k+1)*a[i]-1 当k*a[i] > a[cnt]的时候break
由于a[i] 最大也是20w 所以对于每个数 假设进行的操作是x次 那么总共的次数加起来是玄学的不会超时的...
时间复杂度最差的时候是123...20w 这时候 1是20w 2是10w ... 1000是200次 那么即使1000之前全部20w 1000之后全部200 也只是1000*20w + 20w * 200 其实也只是十的八次方 怎么会超..
当然寻找这z个区间内有多少个数我是手写的二分...后来怎么看时间复杂度都是炸了的..
后来看了一下题解..别人都是直接暴力的..QAQ
D
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
#include<iostream>
#include<queue>
using namespace std;
#define L long long
int n ;
int c;
int a[2][500050];
int len[2];
struct node{
int l,r;
};
node b[2000050];
int l[1000050];
int r[1000050];
int main(){
scanf("%d%d",&n,&c);
int cnt = 1;
int res = 0;
int tot = 0;
bool ok = true;
for(int i=1;i<=n;i++){
cnt ^= 1;
res ^= 1;
scanf("%d",&len[res]);
bool js = false;
for(int k=1;k<=len[res];k++){
scanf("%d",&a[res][k]);
if(i == 1){
continue;
}
if(js == true){
continue;
}
if(k > len[cnt]){
continue;
}
if(a[res][k] == a[cnt][k]){
continue;
}
else if(a[res][k] > a[cnt][k]){
tot ++ ;
b[tot].l = 0;
b[tot].r = c - a[res][k];
if(a[cnt][k] != 1){
tot ++ ;
b[tot].r = c - 1;
b[tot].l = c - 1 - (a[cnt][k] - 2);
}
js = true;
}
else {
tot ++ ;
b[tot].l = c - a[cnt][k] + 1;
b[tot].r = c - a[res][k];
js = true;
}
}
if(i == 1){
continue;
}
if(js == false){
if(len[res] < len[cnt]){
ok = false;
}
else {
tot ++ ;
b[tot].l = 0;
b[tot].r = c-1;
}
}
}
if(n == 1){
printf("0\n");
return 0;
}
if(ok == false){
printf("-1\n");
return 0;
}
for(int i=0;i<=c;i++){
l[i] = r[i] = 0;
}
for(int i = 1; i<= tot;i++){
l[b[i].l] ++ ;
r[b[i].r] ++ ;
//printf("%d %d\n",b[i].l,b[i].r);
}
int sum = 0;
int i;
for(i=0;i<c;i++){
sum += l[i];
if(sum >= n-1){
printf("%d\n",i);
break;
}
sum -= r[i];
}
if(i == c){
printf("-1\n");
}
}
F
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
#include<iostream>
#include<queue>
#include<vector>
using namespace std ;
#define L long long
int n ;
L a[200050];
L b[200050];
L num[200050];
L sum[200050];
int cnt ;
int zerfen(int l,int r ,L Lx,L Rx){
int res = -1;
while(l<=r){
int mid = (l+r)/2;
if(b[mid]>=Lx && b[mid] <= Rx){
res = mid ;
r = mid-1;
}
else {
if(b[mid] < Lx){
l = mid +1;
}
else {
r = mid -1;
}
}
}
return res;
}
int yerfen(int l,int r ,L Lx,L Rx){
int res = -1;
while(l<=r){
int mid = (l+r)/2;
// printf(" L R Mid: %d %d %d\n",l,r,mid);
if(b[mid]>=Lx && b[mid] <= Rx){
res = mid ;
l = mid+1;
}
else {
if(b[mid] < Lx){
l = mid +1;
}
else {
r = mid -1;
}
}
}
return res;
}
int main(){
scanf("%d",&n);
memset(num,0,sizeof(num));
cnt = 0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
if(num[a[i]] == 0){
cnt ++ ;
b[cnt ]= a[i];
}
num[a[i]] ++;
}
sort(b+1,b+1+cnt);
L ans = 0;
sum[0] = 0;
for(int i=1;i<=cnt ;i++){
sum[i] = sum[i-1] + num[b[i]];
}
sum[n+1] = sum[n];
for(int i=1;i<=cnt;i++){
/// i = base
L res = 0;
for(int k= 1;b[i]*(k) <=b[cnt];k++){
int l = i;
int r = cnt ;
L Lx = b[i]*k;
L Rx = b[i]*(k+1);
int zer = zerfen(l,r,Lx,Rx-1);
int yer = yerfen(l,r,Lx,Rx-1);
//printf("zhi : %lld %lld \n",Lx,Rx);
//printf("%d %d\n",zer,yer);
if(zer == -1 || yer == -1){
continue;
}
else {
L z = sum[yer] - sum[zer -1];
res += (z * b[i] * k);
}
}
if(res > ans){
ans = res ;
}
//printf("-------------------------\n");
}
printf("%lld\n",ans);
}
Codeforces Round #376 (Div. 2) C D F的更多相关文章
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力
http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...
- Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和
题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...
- Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和
F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #376 (Div. 2) C题 Socks(dsu+graphs+greedy)
Socks Problem Description: Arseniy is already grown-up and independent. His mother decided to leave ...
- Codeforces Round #376 (Div. 2) D. 80-th Level Archeology —— 差分法 + 线段扫描法
题目链接:http://codeforces.com/contest/731/problem/D D. 80-th Level Archeology time limit per test 2 sec ...
- Codeforces Round #376 (Div. 2)
A 模拟 #include <cstdio> #include <cstring> int Ans; ]; inline ?x:-x;} inline int Min(int ...
- Codeforces Round #376 (Div. 2) C. Socks---并查集+贪心
题目链接:http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,每只都有一个颜色,现在他的妈妈要去出差m天,然后让他每天穿第 L 和第 R 只 ...
- Codeforces Round #376 (Div. 2) A B C 水 模拟 并查集
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- maven junit 单元测试插件配置
单元测试插件配置 pom.xml中增加 <dependency> <groupId>junit</groupId> <artifactId>junit& ...
- 17243 Huzi酱和他的俄罗斯套娃(贪心)
时间限制:500MS 内存限制:65535K 提交次数:15 通过次数:4 收入:12 题型: 编程题 语言: C++;C Description Huzi酱是个非常贪玩的人,除了魔方他还喜欢各 ...
- 循环遍历泛型集合List绑定到table
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false&quo ...
- 【Oracle】Oracle时间日期格式
to_date("要转换的字符串","转换的格式") 两个参数的格式必须匹配,否则会报错. 即按照第二个参数的格式解释第一个参数. to_char(日期,& ...
- Visual Studio: How to change ipch path in Visual Studio 2010 (.sdf, *.opensdf, ...)
Link: http://stackoverflow.com/questions/4315681/how-to-change-ipch-path-in-visual-studio-2010 引用: T ...
- HDU 3078 (LCA+树链第K大)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3078 题目大意:定点修改.查询树中任意一条树链上,第K大值. 解题思路: 先用离线Tarjan把每个 ...
- OpenResy+Lua 利用百度识图 将图片地址解析成文字
LUA代码:(注:LUA里有一个调用百度识图的接口IP:123.125.115.189(stu.baidu.com),不知为什么我的虚拟机无法解析stu.baidu.com,所以我只能PING出IP来 ...
- 自动备份mysql
创建备份文件存放的目录 mkdir /usr/local/dbbak 脚本:vi /usr/local/mysqlback.sh # /bin/bash DB_NAME="dsideal_d ...
- Leetcode SortList
Sort a linked list in O(n log n) time using constant space complexity. 本题利用归并排序即可 归并排序的核心是将两部分合成一部分, ...
- [WP8.1UI控件编程]SemanticZoom控件实现分组列表
11.1.5 SemanticZoom实现分组列表 SemanticZoom控件可以让用户实现一种更加高级的列表,这种列表可以对列表的项目进行分组,同时这个SemanticZoom控件会提供两个具有相 ...