拼多多就做出一道题,是不是没希望了???

分糖果

#include <iostream>
#include <algorithm>
using namespace std;
#define N 15
#define M 105
struct bear{
int index;
int ability;
int jier;
};

bear be[N];
int tang[M];

bool cmp(int a,int b)
{
return a<b;
}
bool cmp1(bear a,bear b)
{
return a.ability>b.ability;
}
bool cmp2(bear a,bear b)
{
return a.index<b.index;
}

int main(){
int n,m;
while(cin>>n>>m){
for(int i=0;i<m;i++)
cin>>tang[i];
int k=0;
for(int i=0;i<n;i++){
cin>>be[i].ability>>be[i].jier;
be[i].index=k++;
}
sort(tang,tang+m,cmp);
sort(be,be+n,cmp1);
for(int i=0;i<n;i++){
for(int j=m-1;j>=0;j--){
if(be[i].jier>=tang[j]){
be[i].jier-=tang[j];
tang[j]=0;
}
else
continue;
}
}
sort(be,be+n,cmp2);
for(int i=0;i<n;i++){
cout<<be[i].jier<<endl;
//cout<<be[i].ability<<" "<<be[i].jier<<endl;
}
}
return 0;
}
全部评论
握手,第二题做一个多小时还是百分之零,想砸电脑
点赞 回复 分享
发布于 2017-09-02 16:58
也只做出这一道
点赞 回复 分享
发布于 2017-09-02 17:01
同,只写了第一道题~
点赞 回复 分享
发布于 2017-09-03 11:33
我应该选错岗位了,全是设计题。唉。心累啊
点赞 回复 分享
发布于 2017-09-02 22:17
给楼主点个赞
点赞 回复 分享
发布于 2017-09-02 22:12
PDD第二题代码,供参考。 import java.util.Scanner; public class Main { static class TreeNode { int father; int me; TreeNode firstChild; TreeNode nextSibling; String str; public TreeNode(String str2) { str = str2; firstChild = null; nextSibling = null; } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); in.nextLine(); TreeNode[] nodes = new TreeNode[N]; for (int i = 0; i < N; i++) { String[] str = in.nextLine().split(" "); nodes[i] = new TreeNode(str[0]); nodes[i].father = Integer.valueOf(str[1]); nodes[i].me = i; } sort(nodes); TreeNode tn = nodes[0]; for (int i = 1; i < N; i++) { TreeNode t = nodes[i]; TreeNode fa = getFather(tn, t.father); TreeNode child = fa.firstChild; if (child != null) { while (child.nextSibling != null) child = child.nextSibling; child.nextSibling = t; } else fa.firstChild = t; } printValues(tn, tn.me, 0); in.close(); } public static void printValues(TreeNode root, int cen, int lie) { if (root == null) return; String temp = ""; String temp2 = ""; if (cen != 0) { for (int i = 0; i < cen - 1; i++) { if (i == 0) { temp += " "; temp2 += " "; continue; } temp += "| "; temp2 += "| "; } temp += "|-- "; temp2 += "`-- "; } if (root.nextSibling != null || lie == 0) System.out.println(temp + root.str); else System.out.println(temp2 + root.str); printValues(root.firstChild, cen + 1, 0); if (root.firstChild != null) printValues(root.firstChild.nextSibling, cen + 1, lie + 1); } public static TreeNode getFather(TreeNode root, int n) { if (root == null || root.me == n) return root; TreeNode tn = getFather(root.firstChild, n); if (tn == null) tn = getFather(root.nextSibling, n); return tn; } public static void sort(TreeNode[] nodes) { for (int i = 0; i < nodes.length; i++) { for (int j = i + 1; j < nodes.length; j++) { if (nodes[i].father > nodes[j].father) { TreeNode t = nodes[i]; nodes[i] = nodes[j]; nodes[j] = t; } else if (nodes[i].father == nodes[j].father) { if (nodes[i].str.compareTo(nodes[j].str) > 0) { TreeNode t = nodes[i]; nodes[i] = nodes[j]; nodes[j] = t; } } } } } } 输出如下: 10 my-app -1 src 0 main 1 java 2 resource 2 webapp 2 test 1 java 6 resource 6 pom.xml 0 my-app |-- pom.xml `-- src |-- main | |-- java | |-- resource `-- test | |-- java | `-- resource
点赞 回复 分享
发布于 2017-09-02 17:12
四题都对了。。。
点赞 回复 分享
发布于 2017-09-02 17:07
第二题是构建多叉树加遍历加字典序输出,会做但是代码量太大,没通过
点赞 回复 分享
发布于 2017-09-02 17:07
java 这种思路写 过不了。 复杂度太高
点赞 回复 分享
发布于 2017-09-02 17:07
我也只做了一道,想哭
点赞 回复 分享
发布于 2017-09-02 17:04
看见你们都这样我就放心了,题怎么这么难
点赞 回复 分享
发布于 2017-09-02 17:03
我也是,就第一道
点赞 回复 分享
发布于 2017-09-02 17:02
就ac第一道,后面三道没有提交过任何代码。
点赞 回复 分享
发布于 2017-09-02 17:01
后面都不想做
点赞 回复 分享
发布于 2017-09-02 16:59
这代码第一眼看还以为我自己写的呢。。。一模一样
点赞 回复 分享
发布于 2017-09-02 16:57

相关推荐

05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
Twilight_m...:表格简历有点难绷。说说个人看法: 1.个人基本情况里好多无意义信息,什么婚姻状况、健康状况、兴趣爱好、户口所在地、身份证号码、邮政编码,不知道的以为你填什么申请表呢。 2.校内实践个人认为对找工作几乎没帮助,建议换成和测开有关的项目,实在没得写留着也行。 3.工作经历完全看不出来是干什么的,起码看着和计算机没啥关系,建议加强描述,写点你在工作期间的实际产出、解决了什么问题。 4.个人简述大而空,看着像AI生成,感觉问题最大。“Python,C,C++成为我打造高效稳定服务的得力工具”、“我渴望凭借自身技术知识与创新能力,推动人工智能技术的应用发展,助力社会实现智能化转型”有种小学作文的美感。而且你确定你个人简述里写的你都会嘛?你AI这块写的什么“深入研究”,发几篇顶会的硕博生都不一定敢这么写。而且你AI这块的能力和软测也完全无关啊。个人简述建议写你对哪些技术栈、哪些语言、哪些生产工具的掌握,写的有条理些,而且最好是和测开强相关的。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 17:37
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务