计蒜客-光合作用

2024-01-23 14:30
文章标签 计蒜客 光合作用

本文主要是介绍计蒜客-光合作用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目链接:https://nanti.jisuanke.com/t/38

 

du熊是个爱学习的孩子,他总喜欢在生活中做一些小实验,这次du熊想研究一下光合作用。

du熊的实验材料有如下几样:神奇的种子,普通的纸箱和一些光源。一开始du熊将种子均匀的种在了箱子底部,你可以将其看成X轴,种子的位置为X轴上的点。然后du熊用纸板将箱子盖住,并在纸板上安装了一些光源(具体见图)。神奇的种子会在有光的情况下一直向上生长直到没光为止。现在du熊想知道当实验结束时每颗种子的高度是多少?

顶上的为光源,光源两边与顶部的夹角都为45°,黄色部分为光照,绿色的为植物。

输入第一行给出一个T,表示测试数据的组数。每组数据的第一行是三个整数n,m,H(1≤n≤100,000, 0≤m≤100,000, 1≤H≤10,000),n表示种子数(编号1-n),m表示光源数,H表示箱子的高度。接下来m行,每行一个整数Xi表示第i个光源在顶部的位置。

对于每组测试数据,请输出n行,每行一个数表示第i颗种子的最终高度。

样例输入
2
7 1 2
4
4 4 1
1
2
3
4
样例输出
0
0
1
2
1
0
0
1
1
1
1
二分找到当前位置的前后。
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 const int maxn = 1e5+5;
 8 int x[maxn];
 9 int main()
10 {
11     int T;
12     cin>>T;
13     while(T--)
14     {
15         int n,m,h;
16         scanf("%d %d %d",&n,&m,&h);
17         for(int i=1;i<=m;i++)
18         {
19             scanf("%d",&x[i]);
20         }
21         sort(x+1,x+m+1);
22         for(int i=1;i<=n;i++)
23         {
24             int ans = 0;
25             int cnt = lower_bound(x+1,x+m+1,i)-x;
26             if(cnt==1&&m!=0)
27             {
28                 ans = max(ans,h-x[cnt]+i);
29             }
30             else if(cnt==m+1&&m!=0)
31             {
32                 ans = max(ans,h-i+x[cnt-1]);
33             }
34             else if(m!=0)
35             {
36                 ans = max(0,max(h-i+x[cnt-1],h-x[cnt]+i));
37             }
38             printf("%d\n",ans);
39         }
40     }
41     return 0;
42 }

 

转载于:https://www.cnblogs.com/littlepear/p/6033783.html

这篇关于计蒜客-光合作用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/636651

相关文章

计蒜客 Skiing 最长路

In this winter holiday, Bob has a plan for skiing at the mountain resort. This ski resort has MM different ski paths and NN different flags situated at those turning points. The ii-th path from the

计蒜客 Half-consecutive Numbers 暴力打表找规律

The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545 and t_i=\frac{1}{2}i(i+1)t​i​​=​2​​1​​i(i+1), are called half-consecutive. For given NN, find the smallest rr which is no smaller than NN

计蒜客 李白喝酒

感觉这题很有趣,虽然是用来举例二进制的 一天,他提着酒壶,从家里出来,酒壶中有酒两斗。他边走边唱: 无事街上走,提壶去打酒。 逢店加一倍,遇花喝一斗。 一路上,他一共遇到店5次,遇到花10次,已知最后一次遇到的是花,他正好把酒喝光。清计算李白遇到店的和花的次序, 有多少可能的方案。 int ans=0;//方案数 for(int i=0;i<(1<<14);i++){//暴力枚

计蒜客 T1797 最小数和最大数

题目链接:https://nanti.jisuanke.com/t/T1797 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>using namespace std;int main(){int counts;cin>>counts;int t

计蒜客 T1725 国王的魔镜

题目链接:https://nanti.jisuanke.com/t/T1725 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <string>using namespace std;unsigned long minLong

计蒜客 T1677 农场周围的道路

题目链接:https://nanti.jisuanke.com/t/T1677 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>using namespace std;void getGroups(int bulls,int k);int gr

计蒜客 T1560 二分查找(一)

题目链接:https://nanti.jisuanke.com/t/T1560 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <algorithm>using namespace std;long long arr[1000

计蒜客 T1319 质数判定一

题目链接:https://nanti.jisuanke.com/t/T1319 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <math.h>using namespace std;bool isprime(long lon

计蒜客 T1109 字符替换

题目链接:https://nanti.jisuanke.com/t/T1109 https://nanti.jisuanke.com/t/T1109 //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <string>using namespace std;int main(){string str;cha

计蒜客 T1044 最大数输出

题目链接:https://nanti.jisuanke.com/t/T1044 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>using namespace std;int main(){int max = INT32_MIN,tmp;for(