2018 “百度之星”程序设计大赛 - 初赛(A)
第二题还算手稳+手快?最后勉强挤进前五百(期间看着自己从两百多掉到494名)
1001 度度熊拼三角 (hdoj 6374)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6374
签到题
题意:给n根木棒 求可以拼出的周长最长的三角形
可以用贪心的思想做 对所有的木棒长度进行排序 取最长的三根进行判断是否可以组成三角形 若不能 舍去最长的一根 每次都选择相邻的三根 for一遍就好
复杂度为O(nlogn)
代码如下
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int maxn=;
int n,ans;
int a[maxn]; int cmp(int a,int b){
return a>b;
} int check(int x){
if(a[x]+a[x+]>a[x+]&&a[x]+a[x+]>a[x+]&&a[x+]+a[x+]>a[x]) return ;
else return ;
} int main(){
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n,cmp);
int flag=;
for(int i=;i<n;i++){
if(check(i)==) {ans=a[i]+a[i+]+a[i+];flag=;break;}
}
if(flag==) printf("%d\n",ans);
else printf("-1\n");
}
return ;
}
1002 度度熊学队列 (hdoj 6375)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6375
因为是用stl里的list做的 对我来说也算是个签到题了 几乎就算是个list的板子题了
题意:rt 讲的非常清楚
没想到居然没有卡 stl 从此有了stl的真香警告(突然开始打算好好学stl了)
代码如下
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <list> using namespace std;
const int maxn=;
list<int>lst[maxn];
int n,q,op,u,v,w,val; void read(int &x){
char ch = getchar();x = ;
for (; ch < '' || ch > ''; ch = getchar());
for (; ch >='' && ch <= ''; ch = getchar()) x = x * + ch - '';
} int main(){
while(scanf("%d%d",&n,&q)!=EOF){
for(int i=;i<=n;i++) lst[i].clear();
while(q--){
read(op);
if(op==){
read(u);read(w);read(val);
if(w==) lst[u].push_front(val);
if(w==) lst[u].push_back(val);
} if(op==){
read(u);read(w);
if(lst[u].empty()) {printf("-1\n");}
else{
if(w==) {printf("%d\n",lst[u].front());lst[u].pop_front();}
if(w==) {printf("%d\n",lst[u].back());lst[u].pop_back();}
}
} if(op==){
read(u);read(v);read(w);
if(w==) lst[u].splice(lst[u].end(),lst[v]);
if(w==){
lst[v].reverse();
lst[u].splice(lst[u].end(),lst[v]);
}
}
}
}
return ;
}
1003 度度熊剪纸条 (hdoj 6376)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6376
比赛的时候没有肝出来……orz
题意:给一个长度为n的序列 全部由0 1组成 可以切k刀 切完后的k+1段可以自由拼接(不可翻转)求最终序列中的前缀1的数量
应该要分四种情况 先上男朋友的代码
代码如下
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std;
const int maxn=1e5+;
int n,k,cnt,cnt1,ans;
int b[];
char s[maxn]; struct node
{
int d,w;
}kk[maxn]; int cmp(node a,node b){
if(a.d==b.d) return a.w<b.w;
else return a.d>b.d;
} void work(int k,int tmp){
for(int i=;i<=cnt;i++){
if(k>=kk[i].w){
tmp+=kk[i].d;
k-=kk[i].w;
}
}
ans=max(ans,tmp);
} int main(){
while(scanf("%d%d",&n,&k)!=EOF){
scanf("%s",s+);
if(k==){
ans=;
for(int i=;i<=n;i++){
if(s[i]=='') ans++;
else break;
}
printf("%d\n",ans);
continue;
}
int num=;
cnt=cnt1=;
for(int i=;i<=n;i++){
if(s[i]==''){
num++;
if(i==n) b[++cnt1]=num;
}
else if(num!=){
if(i-==num) b[++cnt1]=num;
else {kk[++cnt].d=num;kk[cnt].w=;}
num=;
}
}
k++;
ans=;
sort(kk+,kk++cnt,cmp);
if(cnt1==){
work(k,);
work(k-,b[]);
work(k-,b[]);
work(k-,b[]+b[]);
}
else if(cnt1==){
work(k,);
work(k-,b[]);
}
else work(k,);
printf("%d\n",ans);
}
return ;
}
2018 “百度之星”程序设计大赛 - 初赛(A)的更多相关文章
- HDU6383 2018 “百度之星”程序设计大赛 - 初赛(B) 1004-p1m2 (二分)
原题地址 p1m2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- HDU6380 2018 “百度之星”程序设计大赛 - 初赛(B) A-degree (无环图=树)
原题地址 degree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2018 “百度之星”程序设计大赛 - 初赛(A)度度熊学队列 list rope
c++ list使用 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstr ...
- 【2018 “百度之星”程序设计大赛 - 初赛(B)-1004】p1m2(迷之二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6383 题目就是让你求一个整数数组,在进行任意元素 + 1. - 2 操作后,请问在所有可能达到的稳定数 ...
- 【2018 “百度之星”程序设计大赛 - 初赛(B)- 1001】degree
Problem Description 度度熊最近似乎在研究图论.给定一个有 N 个点 (vertex) 以及 M 条边 (edge) 的无向简单图 (undirected simple graph) ...
- 2018 “百度之星”程序设计大赛 - 初赛(B)
degree Accepts: 1581 Submissions: 3494 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 1310 ...
- HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))
度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))
小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 6114 Chess 【组合数】(2017"百度之星"程序设计大赛 - 初赛(B))
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
随机推荐
- 2017-12-14python全栈9期第一天第三节之python历史
python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言 ...
- Thymeleaf中的&&解析问题
1.问题: 最近使用了新的html模板thymeleaf..在模板里使用js语法时遇到问题,&&不能正确的被解析,使用if(a&&b){}可以通过模板解析,但是浏览器上 ...
- 启动oracle的步骤
启动oracle的步骤 Linux下启动oracle分为以下两步: 1.1.启动lsnrctl监听. 1.2.启动数据库实例. 启动oracle监听 首先登陆服务器,切换到oracle用户. [adm ...
- python 生成器和各种推导式
##################################总结############################### 什么是迭代器? 可迭代对象通过__iter__()可以转换成迭代 ...
- 163邮箱SMTP设置
如题要设置系统邮件自动发送 首先注册的网易邮箱要去开通SMTP服务,然后就是端口的设置 授权码 端口
- 在 CentOS6 上安装 Zabbix2.4 Server
#!/bin/bash # # .配置无人值守的安装,定义安装过程中需要用到的一些信息 # mysql_root_pw=root_pw mysql_zabbix_pw=zabbix_pw DBPass ...
- [Linux] [JNI]
使用 javah 生成头文件后, 编写c代码来实现其中声明的函数, 本文主要解决以下问题: (1) 如何生成动态链接库文件 使用如下格式的 gcc 命令可以将 C文件 编译为 .so 文件, 对于其依 ...
- 酷狗.kgtemp文件加密算法逆向
该帖转载于孤心浪子--http://www.cnblogs.com/KMBlog/p/6877752.html 酷狗音乐上的一些歌曲是不能免费下载的,然而用户仍然可以离线试听,这说明有缓存文件,并且极 ...
- JDK源码之ArrayList
序言 ArrayList底层通过数组实现. ArrayList即动态数组,实现了动态的添加和减少元素 需要注意的是,容量拓展,是创建一个新的数组,然后将旧数组上的数组copy到新数组,这是一个很大的消 ...
- android的android.intent.action.MAIN
当我们使用Android Studio创建一个工程并生成一个Activity时,经常可以在清单文件中看到如下的代码 android.intent.action.MAIN:决定应用的入口Activity ...