在十五楼做的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的更多相关文章

  1. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  2. Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力

    http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #376 (Div. 2)

    A 模拟 #include <cstdio> #include <cstring> int Ans; ]; inline ?x:-x;} inline int Min(int ...

  8. Codeforces Round #376 (Div. 2) C. Socks---并查集+贪心

    题目链接:http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,每只都有一个颜色,现在他的妈妈要去出差m天,然后让他每天穿第 L 和第 R 只 ...

  9. 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 ...

随机推荐

  1. 20145223《Java程序程序设计》第8周学习总结

    20145223 <Java程序设计>第8周学习总结 教材学习内容总结 第十四章 NIO与NIO2 ·NIO使用频道(Channel)来衔接数据节点,在处理数据时,NIO可以让你设定缓冲区 ...

  2. Android HttpClient post MultipartEntity - Android 上传文件

    转自[http://blog.csdn.net/hellohaifei/article/details/9707089] 在Android 中使用HttpClient,MultipartEntity ...

  3. Python基础7- 流程控制之循环

    循环: 把一段代码重复性的执行N次,直到满足某个条件为止. 为了在合适的时候,停止重复执行,需要让程序出现满足停止循环的条件.Python中有三种循环(实质只有两种): while循环 for循环 嵌 ...

  4. apache activemq 学习笔记

    0.activemq的概念 activemq实现了jms(java Message server),用于接收,发送,处理消息的开源消息总线. 1.activemq和jms的区别 jms说白了就是jav ...

  5. rJava包---R与Java的接口

    1.安装 版本说明:Win10+R3.2.5+JKD1.7+eclipse-jee-mars-R-win32-x86_64 install.packages("rJava") 2. ...

  6. iOS学习37数据处理之CoreData

    1. CoreData数据库框架的优势 1> CoreData历史 CoreData数据持久化框架是Cocoa API 的一部分,首次在iOS5版本的系统中出现,它允许按照实体-属性-值模型组织 ...

  7. Java classpath 如何自动添加web-content /lib下的jar包

    右键属性--Java build path--Libraries--add library--Web app libraries -- next --next -- ok

  8. BZOJ 1086 & 类树的分块

    题意: “余”人国的国王想重新编制他的 国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两个 不同的城市之间 ...

  9. Android listview与adapter用法

    listview与adapter用法 博客分类: android   一个ListView通常有两个职责. (1)将数据填充到布局. (2)处理用户的选择点击等操作. 第一点很好理解,ListView ...

  10. rem 产生的小数像素问题

    由于日常需求以无线居多,所以可以在业务中做一些尝试,如 rem,刚接触这个特性的时候,曾经一度爱不释手,仿佛在无线开发的坎坷路上寻找到一条捷径.然而随着使用范围的扩大,慢慢的发现了一些使用 rem 带 ...