A. Nuts

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output: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 + 1 sections.

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.

Input

The first line contains four space-separated integers kabv (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.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
3 10 3 3
output
2
input
3 10 1 3
output
3
input
100 100 1 1000
output
1
Note

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.

题意:给你四个数字,k,a,b,v,分别代表着一个盒子最大的section,nut的数量,板的数量,每个section能容纳的最多的nut的数量。让你求出最少可以用几个盒子来装

思路:这个比赛的时候想复杂了,结果就悲剧了。。。。。我分了好多种情况,实际上我分的那些情况如果真拿出来的话能写成很多不同的方法A了这道题T_T。。。。。主要注意一下别让nut的数量小于0还有挡板的数量也要注意

#include <iostream>
#include <stdio.h> using namespace std; int main()
{
int k ,a,b,v ;
while(~scanf("%d %d %d %d",&k,&a,&b,&v))
{
int ans = ;
int temp = (a-)/v+ ;
while(a > )
{
b++ ;
for(int i = ; i <= k && b ; i++)
{
a -= v ;
b -= ;
}
ans++ ;
}
printf("%d\n",ans) ;
}
return ;
}
#include<stdio.h>

int main()
{
int k,a,b,v;
scanf("%d %d %d %d",&k,&a,&b,&v);
int temp = (a-)/v+;//求出放下所有的nut需要多少section
printf("%d\n",max((temp-)/k+,temp-b));//因为结果受制于板的数量和盒子所能容纳的section的数量
return ;
}

B. Trees in a Row

time limit per test: 1 second

                                                                                             memory limit per test:

256 megabytes

input :

standard input

output:

standard output

The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height ai meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all i (1 ≤ i < n),ai + 1 - ai = k, where k is the number the Queen chose.

Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?

Input

The first line contains two space-separated integers: nk (1 ≤ n, k ≤ 1000). The second line contains n space-separated integersa1, a2, ..., an (1 ≤ ai ≤ 1000) — the heights of the trees in the row.

Output

In the first line print a single integer p — the minimum number of minutes the gardener needs. In the next p lines print the description of his actions.

If the gardener needs to increase the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, print on the corresponding line "- j x".

If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.

Sample test(s)
input
4 1
1 2 1 5
output
2
+ 3 2
- 4 1
input
4 1
1 2 3 4
output

0

题意 :n棵树,希望后一棵树比前一棵树高k米,一次可以将一棵树加高若干米或减少若干米,问你最少需要修剪几棵树,然后将具体修剪输出
思路 :这个题比赛的是愣是没反应过来,看了大神的代码才知道思路 ,就是说先找出以谁为基准让别的改变,给出k就可以求每个相对于第一个的增量求出来,然后用自身减这个增量,哈希一下,出现次数最多的那个数就是可以作为基准的,即第一个数,说不清楚,,,,,,
#include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; int a[],b[] ;
int main()
{
int n,k ; while(~scanf("%d %d",&n,&k))
{
int j = ;
memset(b,,sizeof(b)) ;
memset(a,,sizeof(a)) ;
for(int i = ; i < n ; i++)
{
scanf("%d",&a[i]) ;
if(a[i]-i*k > )
b[a[i]-i*k]++ ;
}
for(int i = ; i < ; i++)
if(b[i] > b[j]) j = i ;
printf("%d\n",n-b[j]) ;
for(int i = ; i < n ; i++)
{
if(j != a[i])
{
if(j > a[i])
printf("+ %d %d\n",i+,j-a[i]) ;
else if(j < a[i])
printf("- %d %d\n",i+,a[i]-j) ;
}
j += k ;
}
}
return ;
}

C. Searching for Graph

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill:

  • the graph contains exactly 2n + p edges;
  • the graph doesn't contain self-loops and multiple edges;
  • for any integer k (1 ≤ k ≤ n), any subgraph consisting of k vertices contains at most 2k + p edges.

A subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.

Your task is to find a p-interesting graph consisting of n vertices.

Input

The first line contains a single integer t (1 ≤ t ≤ 5) — the number of tests in the input. Next t lines each contains two space-separated integers: np (5 ≤ n ≤ 24; p ≥ 0; ) — the number of vertices in the graph and the interest value for the appropriate test.

It is guaranteed that the required graph exists.

Output

For each of the t tests print 2n + p lines containing the description of the edges of a p-interesting graph: the i-th line must contain two space-separated integers ai, bi (1 ≤ ai, bi ≤ nai ≠ bi) — two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to n.

Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them.

Sample test(s)
input
1
6 0
output

1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6

题意 :给你n和p,让你构造一个图,满足3个条件,1是这个图刚好有2*n+p条边,2是没有环和重边,3是该图的任何一个只有K个顶点的子图,最多有2*k+p条边
思路 :CF刷人玩儿呢,这么道大水题放在C题,害我只纠结AB了,早知道我先去把C做了,这个分数啊,其实就是按样例那样敲就行了。。。。。
#include <stdio.h>
int main()
{
int T ;
int n, p;
scanf("%d",&T) ;
while(T--)
{
scanf("%d %d",&n,&p) ;
int cnt = ;
for(int i = ; i <= n ; i++)
{
if(cnt == *n+p)
break ;
for(int j = i+ ; j <= n ; j++)
{ printf("%d %d\n",i,j) ;
cnt++ ;
if(cnt == *n+p)
break ;
}
}
}
return ;
}

Codeforces Round #236 (Div. 2)的更多相关文章

  1. 构造图 Codeforces Round #236 (Div. 2) C. Searching for Graph

    题目地址 /* 题意:要你构造一个有2n+p条边的图,使得,每一个含k个结点子图中,最多有2*k+p条边 水得可以啊,每个点向另外的点连通,只要不和自己连,不重边就可以,正好2*n+p就结束:) */ ...

  2. 贪心 Codeforces Round #236 (Div. 2) A. Nuts

    题目传送门 /* 贪心:每一次选取最多的线段,最大能放置nuts,直到放完为止,很贪婪! 题目读不懂多读几遍:) */ #include <cstdio> #include <alg ...

  3. Codeforces Round #236 (Div. 2) C. Searching for Graph(水构造)

    题目大意 我们说一个无向图是 p-interesting 当且仅当这个无向图满足如下条件: 1. 该图恰有 2 * n + p 条边 2. 该图没有自环和重边 3. 该图的任意一个包含 k 个节点的子 ...

  4. Codeforces Round #236 (Div. 2)E. Strictly Positive Matrix(402E)

    E. Strictly Positive Matrix   You have matrix a of size n × n. Let's number the rows of the matrix f ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. nyoj 96 n-1位数(处理前导 0 的情况)

    n-1位数 时间限制:3000 ms  |            内存限制:65535 KB 难度:1   描述 已知w是一个大于10但不大于1000000的无符号整数,若w是n(n≥2)位的整数,则 ...

  2. Web前端发展简史

    Web前端发展简史 有人说“前端开发”是IT界最容易被误解的岗位,这不是空穴来风.如果你还认为前端只是从美工那里拿到切图, JS和CSS一番乱炖,难搞的功能就去网上信手拈来,CtrlC + Ctrl ...

  3. Div+Css的初步运用

    采用DIV+CSS模式的网站具有以下优势:1.表现和内容相分离 2.代码简洁,提高页面浏览速度 3.易于维护和改版 4.提高搜索引擎对网页的索引效率. 然后呢html文件中放置CSS有三种类型:内联. ...

  4. 项目开发笔记-传单下发 名片替换 文件复制上传/html静态内容替换/json解析/html解析

    //////////////////////////// 注意: 此博客是个人工作笔记 非独立demo////////////////////////////////// .............. ...

  5. 默认安装wamp修改MySQL密码

    首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按回车. 然后输入“use mysql”,意思是使用mysql这个数据库,提示“Database changed”就行. ...

  6. OPENSSL中RSA私钥文件(PEM格式)解析【一】

    http://blog.sina.com.cn/s/blog_4fcd1ea30100yh4s.html 在PKCS#1 RSA算法标准中定义RSA私钥语法为: RSAPrivateKey ::= S ...

  7. (九)Hibernate 检索策略

    所有项目导入对应的hibernate的jar包.mysql的jar包和添加每次都需要用到的HibernateUtil.java 这里的hibernate.cfg.xml配置信息我就不再写了 第一节:检 ...

  8. ### core文件使用

    在Linux下程序崩溃,特别是在循环中产生Segment Fault错误时,根本不知道程序在哪出错,这时,利用core文件可以快速找到出错的问题所在. #@author: gr #@date: 201 ...

  9. win7上帝模式

    在win7 系统桌面或任意磁盘下新建文件夹,将文件夹改名为 GodModel.{ED7BA470-8E54-465E-825C-99712043E01C}

  10. javascript学习笔记3

    一 判断下列数值中哪些于false相等? 0, 0.0, 0.000, -0, -0.0, 000, "0",  "0.0", "0.000" ...