递归与排序练习(HDOJ习题)--QQ迁移
来源:互联网 发布:平价婚纱品牌知乎 编辑:程序博客网 时间:2024/05/18 03:26
1029.c(是递归题)
/*使用time[i].x=abs((time[i].h)%12*60+time[i].m-12*time[i].m);则为15MS 176K
使用time[i].x=(time[i].h)%12*60+time[i].m-12*time[i].m;
if(time[i].x<0){
time[i].x*=-1;
}
则为0MS 176K
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct node{
int h;
int m;
int x;
}time[10];
int cmp(const void *a,const void *b){
struct node *c = (struct node *)a;
struct node *d = (struct node *)b;
if(c->x != d->x)
return c->x - d->x;
else
return c->h - d->h;
}
int main(){
int t,i;
scanf("%d",&t);
while(t--){
for(i=0;i<5;i++){
scanf("%2d:%2d",&time[i].h,&time[i].m);
//time[i].x=abs((time[i].h)%12*60+time[i].m-12*time[i].m);
time[i].x=(time[i].h)%12*60+time[i].m-12*time[i].m;
if(time[i].x<0){
time[i].x*=-1;
}
if(time[i].x>=360){
time[i].x=720-time[i].x; //time[i].x-=360;则WA
}
}
qsort(time,5,sizeof(time[0]),cmp);
printf("%02d:%02d\n",time[2].h,time[2].m);//占位符的使用
}
return 0;
}
使用time[i].x=(time[i].h)%12*60+time[i].m-12*time[i].m;
if(time[i].x<0){
time[i].x*=-1;
}
则为0MS 176K
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct node{
int h;
int m;
int x;
}time[10];
int cmp(const void *a,const void *b){
struct node *c = (struct node *)a;
struct node *d = (struct node *)b;
if(c->x != d->x)
return c->x - d->x;
else
return c->h - d->h;
}
int main(){
int t,i;
scanf("%d",&t);
while(t--){
for(i=0;i<5;i++){
scanf("%2d:%2d",&time[i].h,&time[i].m);
//time[i].x=abs((time[i].h)%12*60+time[i].m-12*time[i].m);
time[i].x=(time[i].h)%12*60+time[i].m-12*time[i].m;
if(time[i].x<0){
time[i].x*=-1;
}
if(time[i].x>=360){
time[i].x=720-time[i].x; //time[i].x-=360;则WA
}
}
qsort(time,5,sizeof(time[0]),cmp);
printf("%02d:%02d\n",time[2].h,time[2].m);//占位符的使用
}
return 0;
}
zhbb
1209.double.c
#include <stdio.h>
#include <stdlib.h>
#define EXP 1e-8
typedef struct
{
int hh;
int mm;
double v;
}time;
double myabs(double x)
{
return x>0 ? x : -x;
}
int cmp(const void *a, const void *b)
{
time c = *(time *)a;
time d = *(time *)b;
if (myabs(c.v-d.v)<EXP)
return c.hh - d.hh;
else
return c.v > d.v ? 1 : -1;
}
#include <stdlib.h>
#define EXP 1e-8
typedef struct
{
int hh;
int mm;
double v;
}time;
double myabs(double x)
{
return x>0 ? x : -x;
}
int cmp(const void *a, const void *b)
{
time c = *(time *)a;
time d = *(time *)b;
if (myabs(c.v-d.v)<EXP)
return c.hh - d.hh;
else
return c.v > d.v ? 1 : -1;
}
double gao(int hh, int mm)
{
double h, m, t;
if (hh>=12) hh -= 12;
h = (hh*60+mm)*1.0 / 720;
m = mm * 1.0 / 60;
t = myabs(h-m);
if (t>=0.5)
t = 1 - t;
return t;
}
int main()
{
time a[5];
int t, i;
scanf("%d", &t);
while (t--)
{
for (i=0; i<5; i++)
{
scanf("%d:%d", &a[i].hh, &a[i].mm);
a[i].v = gao(a[i].hh, a[i].mm);
}
qsort(a, 5, sizeof(a[0]), cmp);
printf("%02d:%02d\n", a[2].hh,a[2].mm);
}
return 0;
}
{
double h, m, t;
if (hh>=12) hh -= 12;
h = (hh*60+mm)*1.0 / 720;
m = mm * 1.0 / 60;
t = myabs(h-m);
if (t>=0.5)
t = 1 - t;
return t;
}
int main()
{
time a[5];
int t, i;
scanf("%d", &t);
while (t--)
{
for (i=0; i<5; i++)
{
scanf("%d:%d", &a[i].hh, &a[i].mm);
a[i].v = gao(a[i].hh, a[i].mm);
}
qsort(a, 5, sizeof(a[0]), cmp);
printf("%02d:%02d\n", a[2].hh,a[2].mm);
}
return 0;
}
1209.int.c
#include <stdio.h>
#include <stdlib.h>
#define EXP 1e-8
typedef struct
{
int hh;
int mm;
int v;
}time;
int cmp(const void *a, const void *b)
{
time c = *(time *)a;
time d = *(time *)b;
if (c.v == d.v)
return c.hh - d.hh;
else
return c.v - d.v;
}
#include <stdlib.h>
#define EXP 1e-8
typedef struct
{
int hh;
int mm;
int v;
}time;
int cmp(const void *a, const void *b)
{
time c = *(time *)a;
time d = *(time *)b;
if (c.v == d.v)
return c.hh - d.hh;
else
return c.v - d.v;
}
int gao(int hh, int mm)
{
int h, m, t;
if (hh>=12) hh -= 12;
h = hh * 60 + mm;
m = mm * 12;
t = h-m;
if (t<0) t*=-1;
if (t>=360)
t = 720 - t;
return t;
}
int main()
{
time a[5];
int t, i;
scanf("%d", &t);
while (t--)
{
for (i=0; i<5; i++)
{
scanf("%d:%d", &a[i].hh, &a[i].mm);
a[i].v = gao(a[i].hh, a[i].mm);
}
qsort(a, 5, sizeof(a[0]), cmp);
printf("%02d:%02d\n", a[2].hh,a[2].mm);
}
return 0;
}
{
int h, m, t;
if (hh>=12) hh -= 12;
h = hh * 60 + mm;
m = mm * 12;
t = h-m;
if (t<0) t*=-1;
if (t>=360)
t = 720 - t;
return t;
}
int main()
{
time a[5];
int t, i;
scanf("%d", &t);
while (t--)
{
for (i=0; i<5; i++)
{
scanf("%d:%d", &a[i].hh, &a[i].mm);
a[i].v = gao(a[i].hh, a[i].mm);
}
qsort(a, 5, sizeof(a[0]), cmp);
printf("%02d:%02d\n", a[2].hh,a[2].mm);
}
return 0;
}
0 0
- 递归与排序练习(HDOJ习题)--QQ迁移
- 母函数练习(HDOJ习题)--QQ日志
- 函数与递归练习
- 2011-2012年寒假(HDOJ学习记录)--QQ日志迁移
- 递归练习 数组选择排序
- 数据结构与算法练习-递归
- 匈牙利算法讲解与习题练习
- 递归与冒泡排序
- 递归与归并排序
- 排序练习1:HDOJ 2561 几种简单排序
- 算法导论习题2.3-4 插入排序递归算法2
- [C How To Program] 习题6.32 递归的选择排序
- 算法习题_快速排序的非递归解法
- 递归与非递归插入排序
- 快速排序 递归 与 非递归
- 快速排序之递归与非递归
- 快速排序 递归与非递归
- 归并排序(递归与非递归)
- LeetCode: Insert Interval
- Spring AOP之一 ——AOP的概念
- IOS基础:retain,copy,assign及autorelease
- android 按两次返回键退出程序
- hdu 1569 and hdu 3657 最小割
- 递归与排序练习(HDOJ习题)--QQ迁移
- leetcode Recover Binary Search Tree
- Validate Binary Search Tree--判断一个树是不是二叉查找树(重重重)
- linux dump/restore
- SVM详解
- mysql常用命令(一)
- android assets文件夹、res/raw、res/layout的区别与联系
- 重载(overload)、覆盖(override)、隐藏(hide)
- (四)概率