codeforces #236 div2 简洁题解
A:A. Nuts
1 second
256 megabytes
standard input
standard output
You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x ≥ 0)divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1sections.
You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?
Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.
The first line contains four space-separated integers k, a, b, v (2 ≤ k ≤ 1000; 1 ≤ a, b, v ≤ 1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.
Print a single integer — the answer to the problem.
3 10 3 3
2
3 10 1 3
3
100 100 1 1000
1
In the first sample you can act like this:
- Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts.
- Do not put any divisors into the second box. Thus, the second box has one section for the last nut.
In the end we've put all the ten nuts into boxes.
The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.
花了半个多小时去理清数据的关系,开始感觉无从下手。。。我的方法是:制造相应的盒子,能放多少就尽量放到前面的盒子里面,最后统计一下就可以
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int aa[]; //盒子能放的个数
int main()
{
int k,a,b,v;
cin>>k>>a>>b>>v;
int ans=;
for (int i=;i<=;i++)
aa[i]=v; 初始每个盒子开始只有一个SECTION
for (int i=;i<=;i++)
{
if (b==) break;
if (b+>=k) {aa[i]+=v*(k-);b-=(k-);} 有B则先用
else
{
aa[i]+=b*v;
break;
}
}
int tem=,ll;
for (int i=;i<=;i++)
{
tem+=aa[i];
if (tem>=a) {ll=i;break;}
}
cout<<ll<<endl;
return ;
}
B:题意很简单,构造等差数列,求改变的数的个数最小。。
从A[1]暴力枚举就可,不知为何我从A[N]枚举就挂,白WA5次 #include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int a[],n,k;
int main()
{
cin>>n>>k;
for (int i=;i<=n;i++)
cin>>a[i];
int ans=;
int kk;
for (int i=;i<=;i++)
{
int o=;
int tem=i;
for (int j=;j<=n;j++)
{
if (a[j]!=tem)
o++;
tem+=k;
}
if (o<ans) {ans=o;kk=i;}
} cout<<ans<<endl;
if (ans==) return ;
for (int i=;i<=n;i++)
{
if (a[i]>kk) {cout<<"- "<<i<<" "<<a[i]-kk<<endl;}
else if (a[i]<kk) {cout<<"+ "<<i<<" "<<kk-a[i]<<endl;}
kk+=k;
}
return ;
} C题,我是瞎搞,我的理解是使点连接的边相对稀少,先这样加边:1-->2,2-->3,3-->4,n-1-->n;先见N-1条边,然后:1-->3,2-->4,3-->5,依次;然后是:1--4,2-->5,....感觉这样相对不密集。。#include<iostream>#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int n,p;
int mp[][];
int main()
{
int t;
cin>>t;
while (t--)
{
int m=*n+p;
memset(mp,,sizeof(mp));
cin>>n>>p;
for (int i=;i<n;i++)
mp[i][i+]=;
m=*n+p;
m=m-(n-);
for (int i=;i<n;i++)
{
if (m==) break;
for (int j=;j+i<=n;j++)
{
mp[j][j+i]=;
m--;
if (m==) break;
}
}
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
if (mp[i][j])
cout<<i<<" "<<j<<endl;
}
return ;}还有不得不吐槽自己的码代码能力,太坑了
codeforces #236 div2 简洁题解的更多相关文章
- Codeforces Round div2 #541 题解
codeforces Round #541 abstract: I构造题可能代码简单证明很难 II拓扑排序 III并查集 启发式排序,带链表 IV dp 处理字符串递推问题 V 数据结构巧用:于二叉树 ...
- codeforces 576 div2 A-D题解
A题 Description 题目链接: https://codeforces.com/contest/1199/problem/A 题意: 给定长度为n(1≤n≤100000)的一个序列a,以及两个 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
随机推荐
- Laravel 5 基础(十)- 日期,Mutator 和 Scope
在我们前面的解决方案中,直接给 published_at 赋值为当前日期实际上是一个临时解决方案,我们需要设定发布日期,可能是未来2天后才发布,让我们修改这个问题. 首先修改控制器: public f ...
- ElasticSearch.js
ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java开发的,并作为Apach ...
- 十天学会单片机Day3 D/A与A/D转换器
D/A转换器 1.二进制权电阻网络型D/A转换器 基准电压Vref 数据D(d3d2d1d0) 输出模拟电压V0 i0 = Vref/8R i1 = Vref/4R i2 = Vref/ ...
- swoole 异步队列
安装步骤如下(推荐把安装文件下载到 /usr/local/src 目录下): step 1: wget --no-check-certificate https://github.com/swoole ...
- Django+Nginx+MongoDB+Mysql+uWsgi的搭建
搭建目标如下: 图:系统架构图 这个系统可以提供web服务及其它查询应用服务,我用其做一个二手房信息搜集.处理及分发的系统,可以通过浏览器访问,也可以通过定制的客户端进行访问. 一.安装篇 1.下载安 ...
- App_Store - IOS应用审核的时隐私政策模板
隐私政策 Poposoft尊重并保护所有使用服务用户的个人隐私权.为了给您提供更准确.更有个性化的服务,Poposoft会按照本隐私权政策的规定使用和披露您的个人信息.但Poposoft将以高度的勤 ...
- git用法
chapter: 8 add 添加文件内容至索引 用法:git add [选项] [--] ... -n, --dry-run 演习 -v, --verbose 冗长输出 -i, --interact ...
- 用MSBuild和Jenkins搭建持续集成环境(2)
http://www.infoq.com/cn/articles/MSBuild-2 作者 Mustafa Saeed Haji Ali ,译者 李剑 发布于 2012年10月23日 | 注意: ...
- 2014103《JAVA程序设计》第一周学习总结
本周,在刻苦看了三天课本之后,终于对JAVA这门课程有了一定的认识.了解了JAVA的前世今生,JAVA的三大平台:Java SE.Java EE与Java ME.其中Java SE又可分为四个主要的部 ...
- background-clip
background-clip 用来将背景图片做适当的裁剪以适应实际需要. 语法: background-clip : border-box | padding-box | content-box | ...