第二题还算手稳+手快?最后勉强挤进前五百(期间看着自己从两百多掉到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)的更多相关文章

  1. HDU6383 2018 “百度之星”程序设计大赛 - 初赛(B) 1004-p1m2 (二分)

    原题地址 p1m2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  2. HDU6380 2018 “百度之星”程序设计大赛 - 初赛(B) A-degree (无环图=树)

    原题地址 degree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  3. 2018 “百度之星”程序设计大赛 - 初赛(A)度度熊学队列 list rope

    c++ list使用 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstr ...

  4. 【2018 “百度之星”程序设计大赛 - 初赛(B)-1004】p1m2(迷之二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6383 题目就是让你求一个整数数组,在进行任意元素 + 1. - 2 操作后,请问在所有可能达到的稳定数 ...

  5. 【2018 “百度之星”程序设计大赛 - 初赛(B)- 1001】degree

    Problem Description 度度熊最近似乎在研究图论.给定一个有 N 个点 (vertex) 以及 M 条边 (edge) 的无向简单图 (undirected simple graph) ...

  6. 2018 “百度之星”程序设计大赛 - 初赛(B)

    degree  Accepts: 1581  Submissions: 3494  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 1310 ...

  7. HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))

    度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))

    小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  9. HDU 6114 Chess 【组合数】(2017"百度之星"程序设计大赛 - 初赛(B))

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. scrapy基础二

    应对反爬虫机制 ①.禁止cookie :有的网站会通过用户的cookie信息对用户进行识别和分析,此时可以通过禁用本地cookies信息让对方网站无法识别我们的会话信息 settings.py里开启禁 ...

  2. 关于Django启动创建测试库的问题

    最近项目迁移到别的机器上进行开发,启动Django的时候,有如下提示: Creating test database for alias 'default' 其实这个可能是在Django启动按钮的设置 ...

  3. Java Web之HTML5

    终于学到Java Web这一章节了,首先来了解一下HTML5的一些新知识点吧,我直接贴出HTML5代码看一下: <!DOCTYPE html> <html lang="en ...

  4. java io系列21之 InputStreamReader和OutputStreamWriter

    InputStreamReader和OutputStreamWriter 是字节流通向字符流的桥梁:它使用指定的 charset 读写字节并将其解码为字符.InputStreamReader 的作用是 ...

  5. eclipse没有server选项

    摘录自:https://www.cnblogs.com/xiaoxiaoweng/p/7298183.html 问题描述:eclipse没有server选项 解决问题:找到Help->Insta ...

  6. elasticsearch 集成springboot

    和jpa类似,很简单,很强大. pom <dependencies> <dependency> <groupId>org.springframework.boot& ...

  7. SpringMVC+Shiro不拦截静态资源配置

    最近在弄SpringMVC与Shiro整合,发现如果将DispatcherServlet拦截 *.do这样的URL,就不存在访问不到静态资源的问题.如果DispatcherServlet改为拦截“/” ...

  8. C#与 微信小程序 互为加解密方案

    CryptoJS下载地址: https://code.google.com/archive/p/crypto-js/downloads http://download.csdn.net/detail/ ...

  9. Web项目发布的更新

    在项目发版后经常需要修改bug,解决出现的各种问题,对项目升级,这时候就需要将之前部署,上线的项目更新版本. 本文就简单说一下一些出现的关键点(不到之处欢迎指教) 1.使用idea,eclipse等工 ...

  10. MySQL备份工具之mysqldump使用

    MySQL备份工具之mysqldump使用说明 一.备份分类 根据能否停用数据库,将备份类型分为: 1. 冷备:数据库服务停止后备份 2. 温备:只能对数据库进行读操作,不能进行写操作 3. 热备:在 ...