Codeforces Round #228 (Div. 1)
今天学长给我们挂了一套Div.1的题,难受,好难啊。
Problem A:
题目大意:给你n个数字,让你叠成n堆,每个数字上面的数的个数不能超过这个数,如 3 上面最多放三个数字
问你,最少能放几堆。
刚开始看错题意,以为只要比这个数字小的数都能放上去,后来看清了题意,一直想的是怎么从下往上放,感觉
二分加贪心可以做,但是太麻烦了,后来想如果从上往下放就好做多了,每次从小的开取,这样到取下一个数的
时候就知道上面有多少,能不能取这个数,这样的话也能保证这一堆是最优的。
#include<bits/stdc++.h>
using namespace std;
int a[],n;
bool vis[];
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
int sum=n;
int ans=;
int now=;
while(sum)
{
//cout<<sum<<endl;
for(int i=;i<n;i++)
{
if(!vis[i])
{
if(a[i]>=now)
{
now++;
vis[i]=;
sum--;
}
}
}
ans++;
now=;
}
cout<<ans<<endl;
return ;
}
Problem B:
题目大意:让你给出一幅图,让这幅图从1节点到2节点的最短路的条数为k,且节点个数不能超过1000个。
思路:如果没有节点个数的限制那么这题就非常好些,但有了限制的话其实我们可以这么想,我们可以把
k用2进制表示,这样就能将条数表示成2*2*2...+2*2...的方式。刚写的时候每条单链都是新的,取极限值的
时候会超过1000个节点,于是我就先预处理处一条长度为100的单链重复利用。
#include<bits/stdc++.h>
using namespace std;
int k;
int a[],pos;
bool vis[][];
int len[];//len[i]表示还需要增加i长度的链需要接在那个节点上
int main()
{
vis[][]=vis[][]=;
len[]=;
len[]=;
int ct=;
for(int i=;i>=;i--)
{
vis[i][i-]=vis[i-][i]=;
len[++ct]=i-;
}
cin>>k;
pos=;
while(k)
{
a[pos++]=k&;
k=k>>;
}
pos--;
int cnt=;
for(int i=pos;i>=;i--)
{
if(a[i])
{
for(int j=;j<=i;j++)
{
if(j==)
{
cnt++;
vis[cnt][]=;
vis[][cnt]=;
cnt++;
vis[cnt][]=;
vis[][cnt]=;
}
else
{
cnt++;
vis[cnt][cnt-]=vis[cnt-][cnt]=;
vis[cnt][cnt-]=vis[cnt-][cnt]=;
cnt++;
vis[cnt][cnt-]=vis[cnt-][cnt]=;
vis[cnt][cnt-]=vis[cnt-][cnt]=;
}
}
if(i==pos)
{
vis[cnt][]=vis[][cnt]=;
vis[cnt-][]=vis[][cnt-]=;
}
else
{
if(!i) vis[][len[pos+]]=vis[len[pos+]][]=;
else
{
vis[cnt][len[pos-i+]]=vis[len[pos-i+]][cnt]=;
vis[cnt-][len[pos-i+]]=vis[len[pos-i+]][cnt-]=;
}
}
}
}
cout<<""<<endl;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(vis[i][j] && i!=j) printf("Y");
else printf("N");
}
puts("");
}
return ;
}
Problem C:
题目大意:有n堆牌,A只能从顶部取牌,B只能从底部取牌,A先取,如果每个人都希望自己的点数总和
最大,且每个人的操作都最优,问你最后两个人的点数分别是什么。
思路:这个题还是比较简单的贪心,我们可以这么想,我们把每堆牌都分成上堆和下堆,如果是奇数则
把中间的牌取出来放到一个数组里。如果对A来说下堆有对他有利的大牌,他会想去拿,但是B也是最优
操作,B不会让A拿到,对B来说也是同理,所以最后肯定上堆都是A的下堆都是B的,奇数堆取出来的一
个一个分。
#include<bits/stdc++.h>
using namespace std;
vector<int> zhong;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n;
cin>>n;
int sum1=,sum2=;
for(int i=;i<=n;i++)
{
int m;
scanf("%d",&m);
if(m%==)
{
for(int i=;i<=m;i++)
{
int g;scanf("%d",&g);
if(i<=m/) sum1+=g;
else sum2+=g;
}
}
else
{
for(int i=;i<=m;i++)
{
int g;scanf("%d",&g);
if(i<=m/) sum1+=g;
else if(i==m/+) zhong.push_back(g);
else sum2+=g;
}
}
}
sort(zhong.begin(),zhong.end(),cmp);
for(int i=;i<zhong.size();i++)
{
if(i%==) sum1+=zhong[i];
else sum2+=zhong[i];
}
printf("%d %d\n",sum1,sum2);
return ;
}
Codeforces Round #228 (Div. 1)的更多相关文章
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...
- Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈
C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...
- Codeforces Round #228 (Div. 1) B. Fox and Minimal path 构造
B. Fox and Minimal path 题目连接: http://codeforces.com/contest/388/problem/B Description Fox Ciel wants ...
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心
A. Fox and Box Accumulation 题目连接: http://codeforces.com/contest/388/problem/A Description Fox Ciel h ...
- Codeforces Round #228 (Div. 1) 388B Fox and Minimal path
链接:http://codeforces.com/problemset/problem/388/B [题意] 给出一个整数K,构造出刚好含有K条从1到2的最短路的图. [分析] 由于是要自己构造图,当 ...
- Codeforces Round #228 (Div. 2)
做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...
- Codeforces Round #228 (Div. 2) B. Fox and Cross
#include <iostream> #include <string> #include <vector> #include <algorithm> ...
- Codeforces Round #228 (Div. 2) A. Fox and Number Game
#include <iostream> #include <algorithm> #include <vector> #include <numeric> ...
- Codeforces Round #228 (Div. 1) B
B. Fox and Minimal path time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- centos7 卸载rpm安装的包
1.查看已装包 rpm -qa | grep pgpool 2.卸载包 rpm -e 包名 3.示例(卸载pgpool) [root@VM_145_153_centos etc]# rpm -qa | ...
- Java内存泄露处理
https://www.cnblogs.com/likeli/p/9413830.html
- JavaScript之原生接口类设计
//接口类 var Interface = function(name , methods){ if(arguments.length!=2){ ...
- [HEOI2015]定价 (贪心)
分类讨论大法好! \(solution:\) 先说一下我对这个题目的态度: 首先这一题是贪心,这个十分明显,看了一眼其他题解都是十分优秀的贪心,可是大家都没有想过吗:你们贪心都是在区间\([l,r]\ ...
- d2-admin中那些不错的技巧
d2-admin基于vue-cli3 路由相关 刷新路由,参照官方 组件内的守卫 但是搞不明白为何加了句 render:h => h() { path: 'refresh', name: 'r ...
- python - 类的内置 attr 方法
类的内置 attr 方法 #类的内置 attr 方法: # __getattr__ # __setattr__ # __delattr__ # __getattr__ #到调用一个类不存在数参数时,将 ...
- css scrollbar样式设置
参考链接:https://segmentfault.com/a/1190000012800450
- vc++调用exe获取输出信息
目的 调用命令行程序,返回结果. 思路 把命令行结果输入到管道中,exe的输出信息都存在了strOutput这个变量里. 实现代码 CString strCmd = L"yara64.exe ...
- dellR720服务器设置光盘引导流程安装cenos7
1.开机,按F10,进入系统引导界面,选择加载系统选项,并选择redhat 7.1选项 系统提示不支持,选择仍然继续,根据提示设置BIOS设置启动,重启 2.根据提示按F11进入BIOS启动设置,选择 ...
- 电信运营商 IT 系统介绍
业务支撑系统 BSS: Business support system 运营支撑系统 OSS: Operation support system 管理支撑系统 MSS: Management Su ...