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 ...
随机推荐
- go etcd
etcd介绍 GitHub:https://github.com/coreos/etcd 官网:https://coreos.com/etcd/ 下载:https://github.com/coreo ...
- 图论分支-差分约束-SPFA系统
据说差分约束有很多种,但是我学过的只有SPFA求差分: 我们知道,例如 A-B<=C,那么这就是一个差分约束. 比如说,著名的三角形差分约束,这个大家都是知道的,什么两边之差小于第三边啦,等等等 ...
- weblogic创建控制台启动脚本以及创建服务器
一.创建控制台脚本 二.创建认证文件 通过上面创建的脚本进行启动的时候,会因为密码问题导致起不来,因为在startWebLogic.sh文件中,没有配置用户名和密码.而且通过上面创建的脚本,启动的时候 ...
- Spring Boot笔记七:扩展Spring MVC
新建一个类,继承WebMvcConfigurerAdapter package com.vae.springboot.config; import org.springframework.contex ...
- Linux记录-jstack采集namenode堆栈信息
#!/bin/bash #以hdfs用户执行jstack每分钟采集一次namenode heapstack日志 #mkdir -p /tmp/jstack export JAVA_HOME=/app/ ...
- .net面式题
.Net httphandler与httpmodule区别 动态控件在postback能否保存下来(不能) 序列化(对象到其他格式(xml/json/byte...)JavaScriptSeriali ...
- Github/github 初始化教程
注: 由于将项目迁移到gitee,克隆gitee 的时候出现了问题.不得已,重新配置 ref : https://blog.csdn.net/jingtingfengguo/article/detai ...
- 当php邂逅windows通用上传缺陷
早上逛乌云发现了PKAV大牛的一篇文章,针对php和windows文件上传的分析,思路很YD,果断转之与大家分享. 虽然此文可能有许多的限制条件,但是如果你认真阅读会发现,其实还是比较实用的. 另外一 ...
- spring cloud学习填坑笔记
最近在学习spring cloud,由于学习资料具有普遍性,部分应个人原因导致的小细节问题,往往很难找到解决的办法.这特别记录一下自己遇到的一些问题. 一.eureka-server加入securit ...
- 【1】【leetcode-33,81】 搜索旋转排序数组
(没思路) 33. 搜索旋转排序数组 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给 ...