热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CodeforcesRound#228div1前三题

A题:A.FoxandBoxAccumulationtimelimitpertest1secondmemorylimitpertest256megab

A题:






A. Fox and Box Accumulation



time limit per test

1 second



memory limit per test

256 megabytes



input

standard input



output

standard output


Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th
box can hold at most xi boxes
on its top (we‘ll call xi the
strength of the box).

Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second
and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.

bubuko.com,布布扣

Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more thanxi boxes
on the top of i-th box. What is the minimal number of piles she needs to construct?




Input

The first line contains an integer n (1?≤?n?≤?100).
The next line contains n integers x1,?x2,?...,?xn (0?≤?xi?≤?100).




Output

Output a single integer — the minimal possible number of piles.




Sample test(s)




input

3
0 0 10




output

2




input

5
0 1 2 3 4




output

1




input

4
0 0 0 0




output

4




input

9
0 1 0 2 0 1 1 2 10




output

3






Note

In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.

bubuko.com,布布扣

In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).

bubuko.com,布布扣





题目大意:给你一些物品给出每件物品上面最多放多少箱子,然后求解最少放多少堆。



解题思路:可以采取贪心的策略。这题相对来说比较简单,每次都从可以放最少的箱子数量从上往下放,这样贪心可以求解。



题目地址:A.
Fox and Box Accumulation



AC代码:

#include
#include
#include
#include
#include
#include
using namespace std;
int a[102];
int main()
{
int n,i,x;
while(cin>>n)
{
memset(a,0,sizeof(a));
for(i=0;i {
cin>>x;
a[x]++;
}
int res=0;
while(1)
{
int flag=0;
for(i=0;i<=100;i++)
{
if(a[i])
{
flag=1;
break;
}
}
if(flag==0) break;
int step=0;
for(i=0;i<=100;i++)
{
if((a[i]>=1&&i==step)||(a[i]==1&&step {
a[i]--;
step++;
}
else if(step=2)
{
a[i]--;
step++;
//cout< //continue;
i--;
}
}
//for(i=0;i<=5;i++)
//cout< //cout< res++;
}
cout< }
return 0;
}
/*
3
0 0 10
5
0 1 2 3 4
4
0 0 0 0
9
0 1 0 2 0 1 1 2 10
7
0 2 2 2 3 4 5
*/
这个题目当时写的时候很拙计,虽然样例过了,但是自己随便写了组测试数据就过不了,然后就debug了好久。。






B题:







B. Fox and Minimal path



time limit per test

1 second



memory limit per test

256 megabytes



input

standard input



output

standard output


Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length.
You should calculate the number of shortest paths between vertex 1 and vertex 2."

Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k?




Input

The first line contains a single integer k (1?≤?k?≤?109).




Output

You should output a graph G with n vertexes (2?≤?n?≤?1000).
There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph.

The first line must contain an integer n. Then adjacency matrix G with n rows
and n columns must follow. Each element of the matrix must be ‘N
or ‘Y‘. If Gij is
Y‘, then graph G has a edge connecting vertex i and
vertex j. Consider the graph vertexes are numbered from 1 ton.

The graph must be undirected and simple: Gii =
N‘ and Gij?=?Gji must
hold. And there must be at least one path between vertex 1 and vertex 2. It‘s guaranteed that the answer exists. If there multiple correct answers, you can output any of them.




Sample test(s)




input

2




output

4
NNYY
NNYY
YYNN
YYNN




input

9




output

8
NNYYYNNN
NNNNNYYY
YNNNNYYY
YNNNNYYY
YNNNNYYY
NYYYYNNN
NYYYYNNN
NYYYYNNN




input

1




output

2
NY
YN






Note

In first example, there are 2 shortest paths: 1-3-2 and 1-4-2.

In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.








题目大意:让你构造一张图,使得结点1到结点2最短路走的方法有n种,当然1<=n<=10^9,当时突然灵光一闪就是素数分解,然后就开始写了,不过大于1000的素数是不可以的,因为要求最多只能用1000个点,然后题目有一句话说了:不会给没有答案的n。然后我就抱着庆幸的态度交了。不过最后被hack了。直到最后也没能想通。



解题思路:不过在晚上的时候突然想到了,觉得素数分解不了的话,还可以按照权基数的思想呢,然后早上突然就觉得可以试一下二进制,看了下别人的思路,然后就觉得自己的构造捉急。就是二进制的思想。



每次

1

3 4 5

6 7 8

9 10 11

每次都让3和6,7连着,4和6,7连着.,6连接9,10,7连接9,10.....1连接5,5连接8,8连接11 ,如果到5结点的时候权是1,那么就让5往左边6,7连接即可,如果权是0,那么就不管,最后让最后三个点里面的最左边两个点都连着2,如果k&1==1,那么最后三个点里面最后一个点也连接2.就是这个思想,具体见代码。



由于k最大为10^9<2^30,那么只需要1&#43;90&#43;1个点就可以搞定。



题目地址:B.
Fox and Minimal path



AC代码:

#include
#include
#include
#include
#include
#include
using namespace std;
int mp[100][105];
int main()
{
int k;
int i,j;
while(cin>>k)
{
memset(mp,0,sizeof(mp));
mp[1][5]=1;
if(k&(1<<30))
{
mp[1][3]=1;
mp[1][4]=1;
}
j=3;
for(i=29;i>=1;i--)
{
mp[j][j+3]=1,mp[j][j+4]=1;
mp[j+1][j+3]=1,mp[j+1][j+4]=1;
mp[j+2][j+5]=1;
if(k&(1< {
mp[j+2][j+3]=1;
mp[j+2][j+4]=1;
}
j+=3;
}
mp[90][2]=1,mp[91][2]=1;
if(k&1) mp[92][2]=1;
cout<<92< for(i=1;i<=92;i++)
{
for(j=1;j<=92;j++)
{
if(mp[i][j]||mp[j][i]) cout<<"Y";
else cout<<"N";
}
cout< }
}
return 0;
}


C题:







C. Fox and Card Game



time limit per test

1 second



memory limit per test

256 megabytes



input

standard input



output

standard output


Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.

The players take turns and Ciel takes the first turn. In Ciel‘s turn she takes a card from the top of any non-empty pile, and in Jiro‘s turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took.
The game ends when all piles become empty.

Suppose Ciel and Jiro play optimally, what is the score of the game?




Input

The first line contain an integer n (1?≤?n?≤?100).
Each of the next n lines contains a description of the pile: the first integer in the line issi (1?≤?si?≤?100)
— the number of cards in the i-th pile; then follow si positive
integers c1c2,
..., ck, ..., csi (1?≤?ck?≤?1000)
— the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.




Output

Print two integers: the sum of Ciel‘s cards and the sum of Jiro‘s cards if they play optimally.




Sample test(s)




input

2
1 100
2 1 10




output

101 10




input

1
9 2 8 6 5 9 4 7 1 3




output

30 15




input

3
3 1 3 2
3 5 4 6
2 8 7




output

18 18




input

3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000




output

7000 7000






Note

In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.

In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.








题目大意:看起来是个博弈题目,A,B分别拿物品,总共有n堆物品,每堆物品有s[i]个,从上面到下面分别放,每个物品各自的价&#20540;。A先拿物品,不过他每次只能选择从某一堆最上面拿出物品,而B每次只能选择从某一堆最下面拿出物品。A,B轮流拿物品,A,B都是最优选择使得总价&#20540;最大。问你
A,B最终得分。



解题思路:我想的思路开始觉得是dp,但是觉得无从下手。后来就放弃了,看了下题解,原来贪心就可以搞定。

然后我就举了个例子。

3

3 5 6 7

3 1 2 3

4 4 3 2 1

按照这样,如果A,B每次都拿最大的,结果不一定最优。

A拿的分为:5 6 4 3 2

B拿的分为:7 3 2 1 1

但是实际上B可以先不拿第二堆的3,因为3在最下面,可以先拿第三堆得1,然后就可以拿第二堆的2了。



实际上的得分为:

A拿的分为:5 6 4 3 1

B拿的分为:7 1 2 3 2



通过多找几轮就会发现,每次一堆的最上面一半是给A了,下面一半是给B了,然后再对中间剩余的排序即可。因为是博弈,当然每个人的态度都是一样的,这样也合情合理,实际证明方法也没多想。



题目地址:C.
Fox and Card Game



AC代码:

#include
#include
#include
#include
#include
#include
#include
using namespace std;
vector mq[105];
int xf[105];
int main()
{
int n,s,x;
int i,j;
int a,b;
while(cin>>n)
{
for(i=1;i<=100;i++)
mq[i].clear();
a=0,b=0;
for(i=1;i<=n;i++)
{
cin>>s;
while(s--)
{
cin>>x;
mq[i].push_back(x);
}
}
int t=0;
for(i=1;i<=n;i++)
{
if(!(mq[i].size()&1))
{
for(j=0;j for(;j }
else
{
for(j=0;j xf[t++]=mq[i][j++];
for(;j }
}
sort(xf,xf+t);
int flag=0;
for(i=t-1;i>=0;i--)
{
if(!flag)
{
a+=xf[i];
flag=1;
}
else
{
b+=xf[i];
flag=0;
}
}
cout< }
return 0;
}
/*
2
1 100
2 1 10
1
9 2 8 6 5 9 4 7 1 3
3
3 1 3 2
3 5 4 6
2 8 7
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
*/







推荐阅读
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • 本文介绍了指针的概念以及在函数调用时使用指针作为参数的情况。指针存放的是变量的地址,通过指针可以修改指针所指的变量的值。然而,如果想要修改指针的指向,就需要使用指针的引用。文章还通过一个简单的示例代码解释了指针的引用的使用方法,并思考了在修改指针的指向后,取指针的输出结果。 ... [详细]
  • 本文内容为asp.net微信公众平台开发的目录汇总,包括数据库设计、多层架构框架搭建和入口实现、微信消息封装及反射赋值、关注事件、用户记录、回复文本消息、图文消息、服务搭建(接入)、自定义菜单等。同时提供了示例代码和相关的后台管理功能。内容涵盖了多个方面,适合综合运用。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 在project.properties添加#Projecttarget.targetandroid-19android.library.reference.1..Sliding ... [详细]
author-avatar
有风吹过best
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有