第二题还算手稳+手快?最后勉强挤进前五百(期间看着自己从两百多掉到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. 【MSSQL】SQL Server 设置用户只能查看并访问特定数据库

    #背景 SQL Server实例上有多个服务商的数据库,每个数据库要由各自的服务商进行维护, 为了限定不同服务商商的维护人员只能访问自己的数据库,且不能看到其他服务商的数据库,现需要给各个服务商商限定 ...

  2. SQL Server没有足够的内存继续执行程序

    有一个表的数据特别大,我点击生成脚本的时候,喜欢新建窗口,但是不行,数据量太大了,所以选择保存文件,保存到本地了.然后我点击执行,又报没有内存去执行...还是因为数据量太大了 解决办法,使用sqlcm ...

  3. I/O模型之二:Linux IO模式及 select、poll、epoll详解

    目录: <I/O模型之一:Unix的五种I/O模型> <I/O模型之二:Linux IO模式及 select.poll.epoll详解> <I/O模型之三:两种高性能 I ...

  4. Java中Sax解析XML

    SAX基于事件的解析,解析器在一次读取XML文件中根据读取的数据产生相应的事件,由应用程序实现相应的事件处理逻辑,即它是一种“推”的解析方式:这种解析方法速度快.占用内存少,但是它需要应用程序自己处理 ...

  5. 关于Android Studio开发环境变量的设置(avd启动黑屏)

    之前因为乱按网上的设置导致启动avd启动黑屏,查了很久原来是ANDROID_AVD_HOME变量没有加$符号 以下是正确的环境变量配置 添加环境变量(注意avd中有一个$符号) ANDROID_SDK ...

  6. vue 组件动态 循环

    组件可以是动态的,记录如下 <div v-for="item in arrComponent"> <component v-bind:is="item. ...

  7. None.js 第三步 回调函数【阻塞代码--非阻塞代码】

    阻塞代码实例 var fs = require("fs"); // 导入文件系统 file system var data = fs.readFileSync('input.txt ...

  8. 传入mybatis的xml为Long型时报There is no getter for property named 'VARCHAR' in

    修改前   <insert id="insert" parameterType="com.taotao.pojo.TbContent" >    i ...

  9. 三十五、minishell(3)

    35.1 内容 在当前的 minishell 中,如果执行 date clear 命令等,minishell 会停止: 这是因为引入进程组的时候,mshell 放置在前台进程组,同时之后在子进程中又创 ...

  10. Spring 快速开始 Profile 和 Bean

    和maven profile类似,Spring bean definition profile 有两个组件:声明和激活. [栗子:开发测试环境使用HyperSQL 生产环境使用JNDI上下文根据配置查 ...