QUT——XiaoCai (签到未成功)
来源:互联网 发布:淘宝的销售金额 编辑:程序博客网 时间:2024/06/08 03:41
总结
签到题,最水的一道题,WA了5小时,求心里阴影面积。
下次注意 x / 2 尽量以 x / 2.0 代替 (直接将计算结果带入计算 而不是另申请变量保存)
上题目
题目描述
Network association recruiting is over, WangXiaoCai go to network association training room looking for a position.
Training room is now sit n individuals, because the body width of each person is different, so the position and size of different also. Because of WangXiaoCai's timid, he want a position that can touch someone but do not overlap(This is obviously). Now WangXiaoCai knows the location of all people and their body width,Would you help him find the amount of possible positions?
输入
The first line of the input data contains numbers n and m (1≤n,m≤1000). Then there follow n lines,each of them contains two
space-separated integer numbers: xi wi, where xi — x-coordinate of the
centre of the i-th people, and wi — width of its body (-1000≤xi≤1000,
1≤wi≤1000).输出
Output the amount of possible positions of the position.样例输入 2 2 0 4 6 2
2 3 0 4 5 2
2 2 0 4 5 2 样例输出 4 2 3 提示 m为小菜的宽度
来源
oyy(欧阳学长这题………………)
分析
主要就是求相邻两人之间的距离
如果大于王小菜的宽度就可以有两种坐法
如果等于王小菜的宽度就有1中坐法
如果小于没有
坑爹提示: 人的身体宽度可以为奇数 没错占半个格
上代码
WA了5小时的代码
#include <stdio.h>struct bu{ int people; int wide;}a[10000];int dis[10000], wi, n, count1;void insert1(int num){ int i, j, k; bu ntemp; for (i = 0; i<num; i++) { ntemp = a[i]; for (j = 0; j <= i; j++) { if (a[i].people>ntemp.people) { for (k = i; k>j; k--) a[k] = a[k - 1]; a[j] = ntemp; break; } } }}int main(){ while (scanf_s("%d%d", &n, &wi) != EOF) { count1 = 0; for (int i = 0; i<n; i++) scanf_s("%d%d", &a[i].people, &a[i].wide); insert1(n); for (int i = 1; i<n; i++) { dis[i] = a[i].people - a[i - 1].people - ((a[i].wide + a[i - 1].wide) / 2); if (dis[i]>wi) count1 += 2; else if (dis[i] == wi) count1++; } printf("%d\n", count1 + 2); } return 0;}
答案代码
#include <stdio.h>#include <stdlib.h>typedef struct { int x; int a;} house;int cmp(const void *a, const void *b){ return ((house *)a)->x - ((house *)b)->x;}int main(){ int n, t; // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); while (scanf("%d %d", &n, &t) != EOF){ int sum = 2, i; house h[1000]; for (i = 0; i < n; i++) scanf("%d %d", &h[i].x, &h[i].a); qsort(h, n, sizeof(house), cmp); for (i = 0; i < n - 1; i++) { int f = 0; if (h[i].x + h[i].a / 2.0 + t <= h[i + 1].x - h[i + 1].a / 2.0) { sum++; f++; } if (h[i + 1].x - h[i + 1].a / 2.0 - t >= h[i].x + h[i].a / 2.0) { sum++; f++; } if (f == 2) { if (h[i].x + h[i].a / 2.0 + t == h[i + 1].x - h[i + 1].a / 2.0) { sum--; } } } printf("%d\n", sum); } return 0;}
- QUT——XiaoCai (签到未成功)
- QUT——An Easy Math Problem (三次函数求最大值)
- 比赛补题:QUT——This is not easy (BFS)
- 一切成功源于积累——每日签到
- 签到日历——待续
- PAT程序设计考题——甲级1006 签到问题(求所有签到人的最早时间和最晚时间)
- WebService学习总结(三)——使用JDK开发WebService(自己还未实验成功 呜呜。。。)
- 开源用户界面和布局的套件XiaoCai.WinformUI(美化用户界面利器)
- 《移动端签到》——统计
- MISC杂项签到——writeup
- 我的Android案例—签到日历
- 我的Android案例—签到日历
- 项目中的问题总结——签到取连续签到次数
- QUT:E-Board
- △(提交未成功)【OJ】(二)---E---计算时间差
- ADAM学习之4集群安装(未成功)
- 阿里云 ubuntu 12.4 配置 hush架构(未成功)
- opencv程序在linux下的执行(未成功)
- Linux 下 socket 高并发分析与优化
- hdoj How many integers can you find 1796 (容斥原理&&DFS)
- anaconda 安装pyspider出错
- 【数据结构和算法】排序算法之二:选择排序和堆排序
- 经典数据交换
- QUT——XiaoCai (签到未成功)
- Java方法重载和方法重写的区别介绍
- Git的使用说明
- angularJS学习之路(十七)---自定义指令
- ElasticSearch中分词器组件配置详解
- 欢迎使用CSDN-markdown编辑器
- Python之可读写的socket逻辑
- Java IO 体系结构
- eclipse编译调试tomcat7.0.65