第二题还算手稳+手快?最后勉强挤进前五百(期间看着自己从两百多掉到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. python机器学习-sklearn挖掘乳腺癌细胞(五)

    python机器学习-sklearn挖掘乳腺癌细胞( 博主亲自录制) 网易云观看地址 https://study.163.com/course/introduction.htm?courseId=10 ...

  2. 网络编程基础【day09】:简单socket实例(二)

    本节内容 1.概述 2.socket实例 3.总结 一.概述 之前我们只是介绍了soket的概念和一些逻辑图表,下面我们来看看,socket的客户端和服务端到底是怎么用的? 二.socket实例 2. ...

  3. 设计模式---状态变化模式之备忘录模式(Memento)

    一:概念 用于保存对象的内部状态,并在需要的时候(undo/rollback)回复对象以前的状态 二:应用场景 如果一个对象需要保存状态并可通过undo或rollback等操作恢复到以前的状态时,可以 ...

  4. Memcache在.Net中的使用

    一.Memcache基本概念(socket服务器) 本质:是一个在内存上存储的hash表,key的最大值是255字符,最长过期时间为30天 特点:惰性删除,没有监控数据过期的机制,实现最基本的key- ...

  5. jQuery使用(一):jQuery对象与选择器

    一.简单的一些介绍 1.jQuery是由普通的是由一些系列操作DOM节点的函数和一些其他的工具方法组成的js库. 2.为什么要使用jQuery库? jQuery面向用户良好的设计在使用过程中彻底解放了 ...

  6. HDU - 4578 Transformation(线段树区间修改)

    https://cn.vjudge.net/problem/HDU-4578 题意 4种操作,区间加,区间乘,区间变为一个数,求区间的和.平方和以及立方和. 分析 明显线段树,不过很麻烦..看kuan ...

  7. HDU - 6394 Tree(树分块+倍增)

    http://acm.hdu.edu.cn/showproblem.php?pid=6394 题意 给出一棵树,然后每个节点有一个权值,代表这个点可以往上面跳多远,问最少需要多少次可以跳出这颗树 分析 ...

  8. python socket 编程

    TCP IPv4 # server.py import socket import threading import time s = socket.socket(socket.AF_INET,soc ...

  9. Vuex笔记

    Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式 Vuex - 状态管理器,可以管理你的数据状态(类似于 React的 Redux) 一个 Vuex 应用的核心是 store(仓库,一个 ...

  10. 细说java平台日志组件

    1. java.util.logging JDK自带日志组件,使用方式简单,不需要依赖第三方日志组件.支持将日志打印到控制台,文件,甚至可以将日志通过网络打印到指定主机.相对于第三方独立日志框架来说, ...