Codeforces Round #276 (Div. 1)
a.
给俩数, 求他俩之间二进制数中1最多的,有多个输出最小的;
贪心,从小到大加能加就加,最后可能碰到一个不能加了但是当前数比l小,那么就加上这个数,然后从大到小,能减就减,见到符合条件
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
long long n, l, r;
long long a[];
long long s = , maxa = 1e18;
long long u;
for(long long i = ;; i++){
a[i] = s;
s*=;
u = i;
if(s > maxa)break;
}
//for(int i = 0; i <= u; i++)printf("%lld ", a[i]);
cin>>n;
while(n--){
cin>>l>>r;//printf("*%d", u);
long long sum = ;
for(int i = ; i <= u; i++){
if(sum + a[i] <= r){//cout<<sum<<" "<<a[i]<<endl;
sum += a[i];
}else if(sum < l){
sum += a[i];
for(int k = i-; k >= ; k--){
if(sum - a[k] >= l){
sum -= a[k];
}
if(l <= sum && sum <= r)
break;
}break;
}
}
cout<<sum<<endl;
}
}
You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).
想了半天决定看别人代码, 果然在ai的数据范围上做文章了,就是每次处理出来小于等于i的数中最大的保存到一个数组里,然后找每个小于ai的n倍-1的最大数字,取膜
#include<iostream>
#include<stdio.h>
using namespace std;
const int maxa = ;
int a[maxa], b[maxa];
int main(){
int n;
scanf("%d", &n);
while(n--){int x;scanf("%d", &x);a[x] = x;};
for(int i = ; i < maxa; i++) b[i] = max(b[i-],a[i]);
int maxn = ;
for(int i = ; i < maxa; i++) if(a[i])
for(int k = *i; k < maxa; k+= i) maxn = max(maxn, b[k-] % i);
printf("%d", maxn);
}
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero).
The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.
The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106).
The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109).
Print the maximum possible total sociability of all groups.
简单的来说题意就是给你一段数字,让你分成任意段,每段的值是这一段中的最大值减去最小值,求所有段的值的最大和;
好吧这题也是看别人的代码看了半天才懂;
由于每段的值是最大值-最小值
我们这样定义三个状态,dp[i][1]代表到以i结尾的值;
dp[i][0]代表当前段的最大值已经确定的最大值(这里的值是确定的最大值+前面区段的值)
dp[i][2]代表当前段的最小值是a[i]的值减去a[i];(同上)
那么dp[i][0]可以由dp[i-1][0]过来代表此数字被放弃了,也可以由dp[i-1][1]推过来代表当前区段的最大值为当前数,在这两个中取最大值;
dp[i][1],dp[i][2]同上
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
const long long maxa = ;
long long a[maxa];
long long dp[maxa][];
int main(){
long long n;
cin>>n;
long long x;
//scanf("%d", &x);
cin>>x;
dp[][] = x;
dp[][] = -x;
for(long long i = ; i <= n; i++){
cin>>x;
for(long long k = ; k < ; k++){
dp[i][k] = dp[i-][k];
if(k > ) dp[i][k] = max(dp[i][k], dp[i-][k-] - x);
if(k < ) dp[i][k] = max(dp[i][k], dp[i-][k+] +x);
//printf("%d ", dp[i][k]);
}//puts("");
}cout<<dp[n][]<<endl;
}
Codeforces Round #276 (Div. 1)的更多相关文章
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...
- Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心
A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Des ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- codeforces 484C Strange Sorting Codeforces Round #276 (Div. 1) C
思路:首先 他是对1到k 元素做一次变换,然后对2到k+1个元素做一次变化....依次做完. 如果我们对1到k个元素做完一次变换后,把整个数组循环左移一个.那么第二次还是对1 到 k个元素做和第一次一 ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树
E. Sign on Fence Bizon the Champion has recently finished painting his wood fence. The fence consi ...
- Codeforces Round #276 (Div. 2)
A. Factory 题意:给出a,m,第一天的总量为a,需要生产为a%m,第二天的总量为a+a%m,需要生产(a+a%m)%m 计算到哪一天a%m==0为止 自己做的时候,把i开到1000来循环就过 ...
随机推荐
- python MySQLdb、socket与进线程
1 centos下 安装MySQLdb模块 a 首先需要先安装 setuptool b yum install -y mysql_devel 头文件 c yum install -y python_d ...
- CentOS下php使用127.0.0.1不能连接mysql的解决方法
这篇文章主要介绍了CentOS下php使用127.0.0.1不能连接mysql的解决方法,本文原因是SELINUX导致的连接失败,需要的朋友可以参考下 php代码很简单: 复制代码代码如下: $ser ...
- delphi : 取得网页源码内容
取得网页的源码内容的函数以及调用方法供大家参考: program geturl; uses wininet, windows; //取网页内容 function StrPas(const Str: P ...
- .NET MVC 插件化框架源码
本来想把源码整理了放github上,但最近一直忙,就直接在这里放出来了,还写得不太完整,里面有几个例子,插件上传也没写,只写了插件zip包解压,如果大家在使用中有什么疑问,可以加QQ群:1429391 ...
- css3中的圆角属性
圆角属性:border-radius <style type="text/css"> .content{ border: 1px solid green; width: ...
- HDOJ 1334 Perfect Cubes(暴力)
Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for n > ...
- 关于我们 HerlMax(赫马克斯),奢侈品顶级服装高级定制品牌!
关于我们 HerlMax(赫马克斯),奢侈品顶级服装高级定制品牌! HerlMax品牌拥有着纯正悠远的意大利高级定制文化,带着对神秘东方的向往,荣耀登入中国市场.
- 深入理解linux网络技术内幕读书笔记(七)--组件初始化的内核基础架构
Table of Contents 1 引导期间的内核选项 2 注册关键字 3 模块初始化代码 引导期间的内核选项 linux运行用户把内核配置选项传给引导记录,然后引导记录再把选项传给内核. 在引导 ...
- 写两个线程,一个对n每次加一,一个对n每次减一
public class A{ private static Integer n = 0; } public class B extends A implements Runnable ...
- java--字节数组输入、输出流
在java网络编程中,字节数组很重要,它可以传输任何资料(文本,音频,视频,图片等),因此掌握字节数组和其它数据类型的相互转化尤为重要. 示例代码: package com.lky.util; imp ...