A题:

计算模糊日期的天数,简单思维题,注意long long

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;#define LL long long
int a[100005];int main()
{int n;//freopen("in.txt","r",stdin);while(scanf("%d",&n)!=EOF){for(int i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);LL ans=0;for(int i=0;i<n;i++)if((min(n,a[i])-i-1)>0)ans+=(min(n,a[i])-i-1);printf("%lld\n",ans*2);}return 0;
}

B题:

A year after his bacteria experiment, Jason decided to perform another experiment on a new bacteria specie which evolves in a special way. The initial form of the bacteria can be considered as an undirected tree with N nodes in terms of graph theory. Every hour, an edge (x, y) is built if there exists a node z such that, in the previous hour, there exists edge (x, z) and edge (y, z), but not edge (x, y). The bacteria keep evolving until no more edges can be formed.

The following graph shows a type of bacteria which requires 2 hours to fully evolve:

As it may take months if not years for the bacteria to evolve to its ultimate form, it is impossible for Jason to stay at the laboratory to observe the change of the bacteria throughout the entire process. Therefore, he wants you to calculate the time required for the bacteria to fully evolve, so that he can just get back to the laboratory on time.

Input

The first line contains an integer N. (2 ≤ N ≤ 5 × 105)

The next N - 1 line each contains two integers u and v, which means there exists an edge between node u and v. (1 ≤ u, v ≤ N)

The given graph is guaranteed to be a valid tree.

Output

Output an integer, the time (in hours) required for the bacteria to fully evolve.

Example
Input
6
1 5
5 3
5 6
6 2
6 4

Output
2

题意:

给出一棵树,每一个小时内:只要任意两个点的相邻点中有一个公共点,那么这两点会连一条线

问:会进行多少个小时这样的连线

题解:

找最长链,从任意一个点开始找到一个离他最远的点,再从这个点开始找到另外一个最远的点,这两个点就是两端

比如说 1  2  3  4  5  是一条链,然后1,3    2,4   3,5   ,然后1可以和5连,看得出,只要首尾连接了得到最终的图, 所以答案为 点数 x <=2^n ,的时候,n即为答案

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std;const int maxn=5*1e5+5;typedef pair<int, int> pll;
int n,m;
int d[maxn];
vector<pll> edge[maxn];int bfs(int u)
{queue<int> Q;Q.push(u);d[u]=0;int max_d=0,max_u=u;while(!Q.empty()){u=Q.front(); Q.pop();if(d[u]>max_d)  {max_d=d[u];max_u=u;}for(int i=0;i<edge[u].size();i++){int v=edge[u][i].first;if(d[v]==-1){Q.push(v);d[v]=d[u]+edge[u][i].second;}}}return max_u;
}int main()
{//freopen("in.txt","r",stdin);while(~scanf("%d",&n)){int u,v;for(int i=1;i<=n;i++)  edge[i].clear();for(int i=1;i<n;i++){scanf("%d%d",&u,&v);edge[u].push_back(make_pair(v,1));edge[v].push_back(make_pair(u,1));}memset(d,-1,sizeof(d));int p=bfs(1);memset(d,-1,sizeof(d));int q=bfs(p);int ans=d[q];int tmp = 1, cnt = 0;while(tmp<ans){tmp*=2;cnt++;}printf("%d\n",cnt);}return 0;
}

C题

签到题

找到两个字符串在主字符串的出现的频率,比较大小即可

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;char s[105];int main()
{//freopen("in.txt","r",stdin);while(~scanf("%s",s)){int n = strlen(s);int tot1 = 0, tot2 = 0;for(int i=0;i<n;i++){if(s[i] == 'L'){if(i+1<n && s[i+1]=='S' && i+2<n && s[i+2]=='C')  tot1++;}else if(s[i] == 'P'){if(i+1<n && s[i+1]=='C' && i+2<n && s[i+2]=='M' && i+3<n && s[i+3]=='S') tot2++;}}if(tot1>tot2)  puts("LSC");else if(tot1<tot2)  puts("PCMS");else puts("Tie");}return 0;
}

D题:

给出两天,问这两天之间(包括这两天)的天数内:周日,周一到周六,这些星期各出现了多少天

题解:

模拟即可

H题:

题意:

给出两个圆,这两个圆一定有交集,求交集里面任意一个点输出即可

题解:

圆心连线和小圆的交点输出即可,注意圆心重合的情况

#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;#define LL long long
struct node{LL x,y,r;
}a[5];int main()
{//freopen("in.txt","r",stdin);while(scanf("%lld%lld%lld",&a[1].x,&a[1].y,&a[1].r)!=EOF){scanf("%lld%lld%lld",&a[2].x,&a[2].y,&a[2].r);if(a[1].r<a[2].r) swap(a[1],a[2]);double x1,y1,x2,y2,k,t;if(a[1].x==a[2].x&&a[1].y==a[2].y)printf("%0.7lf %0.7lf\n",a[2].x*1.0,a[2].y*1.0);else if(a[1].x!=a[2].x){k=(a[2].y-a[1].y)*1.0/(a[2].x-a[1].x);t=sqrt(a[2].r*a[2].r*1.0/(1+k*k));x1=t+a[2].x;y1=t*k+a[2].y;x2=-t+a[2].x;y2=-t*k+a[2].y;int flag=-1;double t1=(x1-a[1].x)*(x1-a[1].x)+(y1-a[1].y)*(y1-a[1].y);double t2=(x2-a[1].x)*(x2-a[1].x)+(y2-a[1].y)*(y2-a[1].y);if(t1<t2) printf("%0.7lf %0.7lf\n",x1,y1);else      printf("%0.7lf %0.7lf\n",x2,y2);}else{double t1=a[2].y+a[2].r;double t2=a[2].y-a[2].r;if(fabs(a[1].y-t1)>fabs(a[1].y-t2))printf("%0.7lf %0.7lf\n",a[2].x*1.0,(a[2].y-a[2].r)*1.0);elseprintf("%0.7lf %0.7lf\n",a[2].x*1.0,(a[2].y+a[2].r)*1.0);}}return 0;
}

I题:

给出一个数组,问,如何翻转一个区间内数字的正负值,使得最终数组的相邻数字之差的绝对值和最小

题解:

翻转一个区间只会影响两端的相邻之差的绝对值

K题:

给出一些点,这些点会覆盖一部分区域,然后问你最少需要再加多少个点才能把剩余的区域全部覆盖

很容易看出考虑四周的四个点就可以了

La Salle-Pui Ching Programming Challenge 2017 Gym - 101522A,B,C,D,H,I,K相关推荐

  1. Gym101522GHIJKL----La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017

    La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017 文章目录 La Salle-Pui Ching Programming Challeng ...

  2. La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2016 A~F

    La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2016 A~F 文章目录 La Salle-Pui Ching Programming Chal ...

  3. Gym101521GHIJKL-----La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2016

    La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2016 文章目录 La Salle-Pui Ching Programming Challeng ...

  4. La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017

    A Ambiguous Dates 贪心,从小到大取日期 #include<bits/stdc++.h> using namespace std; #define For(i,n) for ...

  5. gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017...

    西瓜队(划掉),Kuma Rider久违的第一场训练,四小时瞎打.jpg A.水题,排序 #include<cstdio> #include<iostream> #includ ...

  6. 亚马逊采摘挑战赛APC:6D姿态估计的多视图自我监督深度学习6D Pose Estimation in the Amazon Picking Challenge—2017(笔记)

    Multi-view Self-supervised Deep Learning for 6D Pose Estimation in the Amazon Picking Challenge-2017 ...

  7. 【视觉目标跟踪最高峰】VOT Challenge 2017 亚军北邮团队技术分享(附代码)

    视觉跟踪领域国际顶级赛事 Visual-Object-Tracking Challenge (VOT) 2017年结果出炉,结合传统滤波及深度学习的方案取得最佳成绩.本文是第二名北京邮电大学代表团队的 ...

  8. 2017年电赛国赛H题《远程幅频特性测试装置》训练总结(信号接收采集部分)

    系列文章链接目录 一.2017年电赛国赛H题<远程幅频特性测试装置>训练总结(DDS信号源部分) 二.2017年电赛国赛H题<远程幅频特性测试装置>训练总结(放大器部分) 三. ...

  9. Nordic Collegiate Programming Contest 2017 题解

    前几天打了一场外国人的比赛,感觉那边的题目质量还是很好的,区分度很鲜明,题目没有国内的难,坑点比较少,比较注重思维,基础算法. B题: Best Relay Team Picture by Ferna ...

最新文章

  1. Unity C#单例模式的实现
  2. 禁忌搜索算法求解带时间窗的车辆路径问题原理讲解
  3. 销售运作计划(SOP)
  4. ITK:通过指定区域裁剪图像
  5. 温故而知新:HttpApplication,HttpModule,HttpContext及Asp.Net页生命周期
  6. SAP Spartacus里modifiedtime的大小写问题
  7. python getattr和getattribute_python中__getattr__和__getattribute__区别
  8. APP价格标签页设计灵感!多款案例选择!
  9. 威纶触摸屏与三菱D700变频器485通讯程序 自己编写的威纶触摸屏与台达变频器的通讯程序
  10. STC单片机 EEPROM和低功耗笔记
  11. JavaScript替换字符串中括号里的内容
  12. 真格量化常见报错信息和Debug方法
  13. 用数据全方位解读《欢乐颂2》
  14. matlab演奏《起风了》代码
  15. css竖向箭头符号_如何使用CSS制作箭头符号
  16. 2019 10月 月末总结
  17. android手机wifi快的办法,手机wifi如何设置网速变快(这样设置网速瞬间堪比5G)...
  18. 卡巴虚拟机启发式查毒的绕过方法
  19. 中石油acm训练赛NO.9(小X与煎饼)
  20. PIL获取照片exif 批量修改手机照片名字为拍摄时间

热门文章

  1. 如何让自己的CS水平更进一步?(一)准备技巧
  2. Micropython——基于utime库实现程序执行时间的计时
  3. 计算机毕业设计Java京津冀畅游网设计(源码+系统+mysql数据库+lw文档)
  4. Vue中的solt插槽
  5. 如何更改win7任务管理器的背景。ctrl+alt+delete调出来的界面的背景
  6. 用python+pygame写的宝石迷阵小游戏
  7. android 录制视频过程中拍照,GitHub - 616852636/CameraView: 仿微信拍照Android控件(点击拍照,长按录小视频)...
  8. 可穿戴设备数据监测登榜2016十大医疗创新
  9. removeIf用法
  10. NeurIPS 2021 Spotlight | 准确、快速、内存经济,新框架MEST实现边缘设备友好的稀疏训练...