0%

在下面的一段程序中,我的想法是认为只输出一个a,因为之行一次WaitForSingleObject(mutex,INFINITE);后,互斥变量的mutex就已经被占用了,第二次将会一直等着哪里,可是结果却出乎人的意料,输出无限多个a

1
2
3
4
5
6
HANDLE mutex = CreateMutex(NULL,false,NULL);
while(true)
{
WaitForSingleObject(mutex,INFINITE);
cout<<"a"<<endl;
}

经过几番查找之后才发现,原来WaitForSingleObject(mutex,INFINITE);这个函数跟线程本身有关,当一个线程使用WaitForSingleObject(mutex,INFINITE);函数的时候,mutex就被该线程标记为占用了,如果该线程没有进行ReleaseMutex操作的话,其他线程就不能用这个mutex,而占用mutex的线程能则可以多次执行WaitForSingleObject(mutex,INFINITE);并且会将mutex的计数一直增加,只有当拥有mutex的线程相应多次调用ReleaseMutex其他线程才可以使用mutex互斥量

简介:本游戏是基于Java手机上的J2ME开发。本游戏是一个拼图游戏,内置10张图片,每次游戏开始由系统随机抽取一张图片作为源图,然后随机乱序,通过上下左右四个按键进行移动,自动检测过关情况,若发现新的记录,由用户保存新纪录。这是我第一款正式编码的手机程序,在电脑的模拟器上运行正常,若移植到真机上,可能(很大可能)存在很多BUG,本程序对手机要求中上,要能支持java,并且性能和内存上要有一定的高度,本人都手机(Motorola V3ie)支持java,本程序在本人手机上能安装,但是无法正常运行,应该是我的机子比较落后,在同学手机(Nokia)上能够运行正常,本程序或许会因为手机的型号不同出现差异,这是不可避免的。需要源码联系qq1023400273哦

阅读全文 »

最近在做一个程序,要用到类似于vc中的CListCtrl控件功能,和QQ好友列表的那种图标一样,选定图标后会变蓝,API看了很久都没有发现比较有用的信息,只看到一个JLabel和那个比较相似,但是JLabel直接加到JList里面的话会出现不能选定,也就是选定后不变蓝的情况,而后在网络上得到的信息实现ListCellRenderer接口,然后对选定的JLabel设定背景颜色,而为了实现绘制JLabel的背景颜色,你不得不重写一个类继承JLabel并且重写paintComponent方法进行背景颜色的绘制,

效果图如下:
Alt text

阅读全文 »

Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 5897 Accepted: 1843

Description

Li Ming is a good student. He always asks the teacher about his rank in his class after every exam, which makes the teacher very tired. So the teacher gives him the scores of all the student in his class and asked him to get his rank by himself. However, he has so many classmates, and he can’t know his rank easily. So he tends to you for help, can you help him?

阅读全文 »

Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9629 Accepted: 5758

Description

The cows in farmer John’s herd are numbered and branded with consecutive integers from 1 to N (1 <= N <= 10,000,000). When the cows come to the barn for milking, they always come in sequential order from 1 to N.

Farmer John, who majored in mathematics in college and loves numbers, often looks for patterns. He has noticed that when he has exactly 15 cows in his herd, there are precisely four ways that the numbers on any set of one or more consecutive cows can add up to 15 (the same as the total number of cows). They are: 15, 7+8, 4+5+6, and 1+2+3+4+5.

When the number of cows in the herd is 10, the number of ways he can sum consecutive cows and get 10 drops to 2: namely 1+2+3+4 and 10.

Write a program that will compute the number of ways farmer John can sum the numbers on consecutive cows to equal N. Do not use precomputation to solve this problem.

阅读全文 »

Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3448 Accepted: 2318

Description

Most positive integers may be written as a sum of a sequence of at least two consecutive positive integers. For instance,
6 = 1 + 2 + 3
9 = 5 + 4 = 2 + 3 + 4but 8 cannot be so written.

Write a program which will compute how many different ways an input number may be written as a sum of a sequence of at least two consecutive positive integers.

阅读全文 »

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3652 Accepted: 2065

Description

Tan Your Hide, Inc., owns several coin-operated tanning salons. Research has shown that if a customer arrives and there are no beds available, the customer will turn around and leave, thus costing the company a sale. Your task is to write a program that tells the company how many customers left without tanning.

阅读全文 »

Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6666 Accepted: 3585

Description

Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in this area has resulted in the practical use of results from number theory and other branches of mathematics once considered to be only of theoretical interest.
This problem involves the efficient computation of integer roots of numbers.
Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the nth. power, for an integer k (this integer is what your program must find).

阅读全文 »

Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6666 Accepted: 3585

Description

Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in this area has resulted in the practical use of results from number theory and other branches of mathematics once considered to be only of theoretical interest.
This problem involves the efficient computation of integer roots of numbers.
Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the nth. power, for an integer k (this integer is what your program must find).

阅读全文 »

Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10654 Accepted: 5029

Description

Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text input (no more than 72 characters per line) from the input file and print a vertical histogram that shows how many times each letter (but not blanks, digits, or punctuation) appears in the all-upper-case input. Format your output exactly as shown.

阅读全文 »