王大头's profile王大头PhotosBlogListsMore ![]() | Help |
王大头简单就好 6/11/2009 heaven is a place on earth 歌手:carlisle belinda 专辑:heaven on earth When the night falls down I wait for you And you come around And the world's alive With the sound of kids On the street outside When you walk into the room Carlisle Belinda You pull me close and we start to move And we're spinning with the stars above And you lift me up in a wave of love... Ooh, baby, do you know what that's worth ? Ooh heaven is a place on earth They say in heaven love comes first We'll make heaven a place on earth Ooh heaven is a place on earth When I feel alone I reach for you When I'm lost at sea I hear your voice And it carries me In this world we're just beginning To understand the miracle of living Baby I was afraid before But I'm not afraid anymore Ooh, baby, do you know what that's worth ? Ooh heaven is a place on earth They say in heaven love comes first We'll make heaven a place on earth Ooh heaven is a place on earth 2/27/2009 老黄瓜刷绿漆今天装嫩被鄙视了……
在globaltestmarket注册帐号有两三年了,回答回答问卷赚点积分,到现在才累计不到700积分,一般1000积分才能兑现一次,1000积分折合50美元。 今天遇到个调查学生上网习惯的调查,心想这下赚到了,平时的问卷前面几个试题是判断被调查者是否满足调查要求的,如果不符合要求就只给5个积分。第一个问题是出生年份,四位数字,俺就随便写了个八零后期年份,还好一路顺利,答了半个小时终于弄完了,眼看60积分就到手了。结果最后一个问题是再次确认出生年份……结果就是 我把编的出生年份给忘了……忘了……忘了…… 10/31/2008 POJ 1099 Square Ice用最矬的办法总算过去了,有需要的同学仅用来验证正确性吧。没有什么参考价值。
/*************************************************************/
#include <stdio.h>
#include <string.h> char grid[64][64];
int M, input[16][16], style_rank[4]; void read_data()
{ int i, j; memset(input, 0, sizeof(input));
memset(grid, ' ', sizeof(grid)); for(i = 0; i < M; i++)
for(j = 0; j < M; j++) scanf("%d", &input[i][j]); return;
} void paint_edge()
{ int i; for(i = 0; i < 4 * M + 3; i++)
{ grid[0][i] = '*'; grid[4 * M - 2][i] = '*'; } for(i = 0; i < 4 * M - 1; i++)
{ grid[i][0] = '*'; grid[i][4 * M + 2] = '*'; grid[i][4 * M + 3] = 0; } return;
} void paint_elmt(int i, int j, int type, int style)
{ if(type == 0) { switch(style) { case 1: strncpy(grid[i] + j, "O-H", 3); grid[i + 1][j] = '|'; grid[i + 2][j] = 'H'; break; case 2: strncpy(grid[i] + j, "H-O", 3); grid[i + 1][j + 2] = '|'; grid[i + 2][j + 2] = 'H'; break; case 3: grid[i - 2][j + 2] = 'H'; grid[i - 1][j + 2] = '|'; strncpy(grid[i] + j, "H-O", 3); break; case 4: default: grid[i - 2][j] = 'H'; grid[i - 1][j] = '|'; strncpy(grid[i] + j, "O-H", 3); break; } } else if(type == 1) { strncpy(grid[i] + j, "H-O-H", 5); } else { grid[i - 2][j] = 'H';
grid[i - 1][j] = '|'; grid[i][j] = 'O'; grid[i + 1][j] = '|'; grid[i + 2][j] = 'H'; } return;
} int try_apply(int i, int j, int type, int style)
{ if(type == 0) { if(j + 2 > 4 * M + 1) return 1; switch(style)
{ case 1: if(i + 2 > 4 * M - 3 || (j - 2 > 0 && grid[i][j - 2] == 'O') || grid[i][j - 1] == '*') return 1; break; case 2: if(i + 2 > 4 * M - 3 || (j - 2 > 0 && grid[i][j - 2] == 'H') || grid[i][j + 3] == '*') return 1; break; case 3: if((i - 2 > 0 && grid[i - 2][j + 2] == 'H') || (j - 2 > 0 && grid[i][j - 2] == 'H') || (i - 4 > 0 && grid[i - 4][j + 2] == 'H') || grid[i][j + 3] == '*') return 1; break; case 4: if((i - 2 > 0 && grid[i - 2][j] == 'H') || (j - 2 > 0 && grid[i][j - 2] == 'O') || (i - 4 > 0 && grid[i - 4][j] == 'H') || grid[i][j - 1] == '*') return 1; break; default: break; } } else if(type == -1) { if(i - 2 < 0 || i + 2 > 4 * M - 3 || (i - 2 > 0 && grid[i - 2][j] == 'H') || (i - 4 > 0 && grid[i - 4][j] == 'H')) return 1; } else { if(j + 5 > 4 * M + 2) return 1; } return 0;
} int paint_grid(int i, int j, int m, int n)
{ char grid_bak[64][64]; int ret, step, style; if(m == M)
return 0; memset(grid_bak, 0, sizeof(grid));
memcpy(grid_bak, grid, sizeof(grid)); if(input[m][n])
{ step = (input[m][n] > 0) ? 6 : 2; if(try_apply(i, j, input[m][n], 0))
return -1; paint_elmt(i, j, input[m][n], 0);
if(n == M - 1)
ret = paint_grid(i + 4, 1, m + 1, 0); else ret = paint_grid(i, j + step, m, n + 1); if(ret)
{ memcpy(grid, grid_bak, sizeof(grid)); return -1; } else { return 0; } } else { for(style = 0; style < 4; style++) { if((m == 0 && style_rank[style] > 2) || (m == M - 1 && style_rank[style] < 3)) continue; if((n == 0 && (style_rank[style] == 1 || style_rank[style] == 4))
|| (n == M - 1 && (style_rank[style] == 2 || style_rank[style] == 3))) continue; if(try_apply(i, j, input[m][n], style_rank[style]))
continue; paint_elmt(i, j, input[m][n], style_rank[style]);
if(n == M - 1)
ret = paint_grid(i + 4, 1, m + 1, 0); else ret = paint_grid(i, j + 4, m, n + 1); if(ret)
{ memcpy(grid, grid_bak, sizeof(grid)); continue; } else { return 0; } }
return -1;
} return 0;
} void print_grid()
{ int i; for(i = 0; i < 4 * M - 1; i++)
printf("%s\n", grid[i]); printf("\n"); } void init_rank()
{ int i; style_rank[0] = 3;
style_rank[1] = 4; style_rank[2] = 1; style_rank[3] = 2; return;
} int main()
{ int i = 1; init_rank();
while(scanf("%d", &M) != EOF)
{ if(M == 0) break; read_data();
printf("Case %d:\n\n", i++);
paint_edge();
paint_grid(1, 1, 0, 0);
print_grid();
} return 0;
} /*************************************************************/ 10/24/2008 HP-UX 高精度定时器测试测试代码
/*********************************************************************************/
#include <stdio.h>
#include <stdlib.h> #include <time.h> #include <sys/time.h> #include <errno.h> #include <string.h> #include <unistd.h> #include <pthread.h> #include <sys/types.h> #define PRINT_USEAGE { \
fprintf(stderr,"\n Usage: %s usec ",argv[0]); \ fprintf(stderr,"\n\n");\ } int
main (int argc, char **argv) { unsigned int nTimeTestSec = 0; /* sec */ unsigned int nTimeTest = 0; /* usec */ struct timeval tvBegin; struct timeval tvNow; int ret = 0; unsigned int nDelay = 0; /* usec */ fd_set rfds; struct timeval tv; int fd = 1; int i = 0; struct timespec req; unsigned int delay[20] = { 500000, 100000, 50000, 10000, 1000, 900, 500, 100, 10, 1, 0 };
int nReduce = 0; /* Îó²î */ pthread_cond_t my_cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER; #if 0
if (argc < 2) { PRINT_USEAGE; exit (1); } nDelay = atoi (argv[1]); #endif pthread_cond_init(&my_cond, NULL);
pthread_mutex_init(&my_mutex, NULL); fprintf (stderr, "%-24s%12s%12s%12s\n", "function", "time(usec)", "realTime", "reduce");
fprintf (stderr, "---------------------------------------------------------------------\n"); for (i = 0; i < 20; i++)
{ if (delay[i] <= 0) break; nDelay = delay[i]; /* test usleep */
gettimeofday (&tvBegin, NULL); ret = usleep (nDelay); if (-1 == ret) { fprintf (stderr, "usleep error . errno=%d [%s]\n", errno, strerror (errno)); } gettimeofday (&tvNow, NULL); nTimeTest = (tvNow.tv_sec - tvBegin.tv_sec) * 1000000 + tvNow.tv_usec - tvBegin.tv_usec; nReduce = nTimeTest - nDelay; fprintf (stderr, "%-24s%12u%12u%12d\n", "usleep", nDelay, nTimeTest,nReduce); /* test nanosleep */ gettimeofday (&tvBegin, NULL); req.tv_sec = nDelay / 1000000; req.tv_nsec = (nDelay % 1000000) * 1000; ret = nanosleep (&req, NULL); if (-1 == ret) { fprintf (stderr, "nanosleep %8u not support\n", nDelay); } else { gettimeofday (&tvNow, NULL); nTimeTest = (tvNow.tv_sec - tvBegin.tv_sec) * 1000000 + tvNow.tv_usec - tvBegin.tv_usec; nReduce = nTimeTest - nDelay; fprintf (stderr, "%-24s%12u%12u%12d\n", "nanosleep", nDelay, nTimeTest, nReduce); } /* test select */
gettimeofday (&tvBegin, NULL); FD_ZERO (&rfds); FD_SET (fd, &rfds); tv.tv_sec = 0; tv.tv_usec = nDelay; ret = select (0, NULL, NULL, NULL, &tv); if (-1 == ret) { fprintf (stderr, "select error . errno=%d [%s]\n", errno, strerror (errno)); } gettimeofday (&tvNow, NULL); nTimeTest = (tvNow.tv_sec - tvBegin.tv_sec) * 1000000 + tvNow.tv_usec - tvBegin.tv_usec; nReduce = nTimeTest - nDelay; fprintf (stderr, "%-24s%12u%12u%12d\n", "select", nDelay, nTimeTest, nReduce); /* test pthread_cond_timedwait */
gettimeofday (&tvBegin, NULL); req.tv_nsec = (tvBegin.tv_usec + (nDelay % 1000000)) * 1000; req.tv_sec = tvBegin.tv_sec + nDelay / 1000000 + req.tv_nsec / 1000000000; req.tv_nsec = req.tv_nsec % 1000000000; pthread_mutex_lock(&my_mutex);
pthread_cond_timedwait(&my_cond, &my_mutex, &req); pthread_mutex_unlock(&my_mutex); gettimeofday (&tvNow, NULL);
nTimeTest = (tvNow.tv_sec - tvBegin.tv_sec) * 1000000 + tvNow.tv_usec - tvBegin.tv_usec; nReduce = nTimeTest - nDelay; fprintf (stderr, "%-24s%12u%12u%12d\n", "pthread_cond_timedwait", nDelay, nTimeTest, nReduce); } pthread_cond_destroy(&my_cond);
pthread_mutex_destroy(&my_mutex); return 0;
} /*********************************************************************************/
设置hires_timeout_enable之前
/*********************************************************************************/
function time(usec) realTime reduce
--------------------------------------------------------------------- usleep 500000 516497 16497 nanosleep 500000 509710 9710 select 500000 509819 9819 pthread_cond_timedwait 500000 509816 9816 usleep 100000 109857 9857 nanosleep 100000 109765 9765 select 100000 109810 9810 pthread_cond_timedwait 100000 109854 9854 usleep 50000 59873 9873 nanosleep 50000 59767 9767 select 50000 59807 9807 pthread_cond_timedwait 50000 59858 9858 usleep 10000 19842 9842 nanosleep 10000 19733 9733 select 10000 19808 9808 pthread_cond_timedwait 10000 19856 9856 usleep 1000 19846 18846 nanosleep 1000 19758 18758 select 1000 9816 8816 pthread_cond_timedwait 1000 19857 18857 usleep 900 19869 18969 nanosleep 900 19945 19045 select 900 9618 8718 pthread_cond_timedwait 900 19854 18954 usleep 500 19848 19348 nanosleep 500 19758 19258 select 500 9910 9410 pthread_cond_timedwait 500 19779 19279 usleep 100 19835 19735 nanosleep 100 19758 19658 select 100 9825 9725 pthread_cond_timedwait 100 19851 19751 usleep 10 19854 19844 nanosleep 10 19748 19738 select 10 9862 9852 pthread_cond_timedwait 10 20024 20014 usleep 1 19642 19641 nanosleep 1 19797 19796 select 1 9782 9781 pthread_cond_timedwait 1 10 9 /*********************************************************************************/
可见HP-UX定时器时间精度大概在10ms左右
设置hires_timeout_enable之后
/*********************************************************************************/
function time(usec) realTime reduce
--------------------------------------------------------------------- usleep 500000 500121 121 nanosleep 500000 500024 24 select 500000 511024 11024 pthread_cond_timedwait 500000 500083 83 usleep 100000 100093 93 nanosleep 100000 100030 30 select 100000 109039 9039 pthread_cond_timedwait 100000 100057 57 usleep 50000 50073 73 nanosleep 50000 50018 18 select 50000 59141 9141 pthread_cond_timedwait 50000 50038 38 usleep 10000 10105 105 nanosleep 10000 10023 23 select 10000 19047 9047 pthread_cond_timedwait 10000 10052 52 usleep 1000 1083 83 nanosleep 1000 1026 26 select 1000 17207 16207 pthread_cond_timedwait 1000 1111 111 usleep 900 984 84 nanosleep 900 922 22 select 900 16120 15220 pthread_cond_timedwait 900 977 77 usleep 500 592 92 nanosleep 500 529 29 select 500 17159 16659 pthread_cond_timedwait 500 587 87 usleep 100 205 105 nanosleep 100 124 24 select 100 8350 8250 pthread_cond_timedwait 100 188 88 usleep 10 173 163 nanosleep 10 130 120 select 10 8757 8747 pthread_cond_timedwait 10 205 195 usleep 1 155 154 nanosleep 1 125 124 select 1 8805 8804 pthread_cond_timedwait 1 23 22 /*********************************************************************************/
除了select保持在10ms左右,其他api精度提高到200us以内。和hp的手册说的一致。
hires_timeout_enable is a dynamic tunable that enables/disables
support for high resolution timers and timed sleep for the following Application Programming Interfaces (APIs) - nanosleep, getitimer, setitimer, sigtimedwait, timer_gettime, timer_settime, ualarm, usleep, and pthread_cond_timedwait. With the higher resolution, these interfaces can be expected to support time intervals less than the current 10 ms. |
|
||||
|
|