Click here to Skip to main content
15,888,221 members

onlinewan - Professional Profile



Summary

    Blog RSS
10
Authority
18
Debator
124
Organiser
426
Participant
0
Author
0
Editor
0
Enquirer
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
General带有扩展功能的ListCtrl Pin
onlinewan20-May-10 21:00
onlinewan20-May-10 21:00 
General[MFC]当Explorer进程重启后,确保程序的托盘图标还正常显示在任务栏中 Pin
onlinewan26-Apr-10 20:09
onlinewan26-Apr-10 20:09 
General用VC开发截图小工具 Pin
onlinewan20-Apr-10 21:56
onlinewan20-Apr-10 21:56 
GeneralCComboBox的下拉列表实现自适应宽度 Pin
onlinewan13-Apr-10 17:02
onlinewan13-Apr-10 17:02 
General给刚刚毕业或即将毕业的同学一封信---从自身经历谈找工作 Pin
onlinewan30-Mar-09 17:48
onlinewan30-Mar-09 17:48 
General计划为什么不能如期完成? Pin
onlinewan26-Mar-09 17:29
onlinewan26-Mar-09 17:29 
General在ARX中利于Automation打开、新建DWG文件 Pin
onlinewan22-Mar-09 15:33
onlinewan22-Mar-09 15:33 
General收藏 [modified] Pin
onlinewan15-Mar-09 16:19
onlinewan15-Mar-09 16:19 
General企业制度与文化 Pin
onlinewan10-Mar-09 23:06
onlinewan10-Mar-09 23:06 
General2005年百度之星程序设计大赛试题初赛题目三 Pin
onlinewan3-Nov-08 19:06
onlinewan3-Nov-08 19:06 
General2005年百度之星程序设计大赛试题初赛题目二 Pin
onlinewan3-Nov-08 19:02
onlinewan3-Nov-08 19:02 
题目描述:请编写程序,找出下面 “ 输入数据及格式 ” 中所描述的输入数据文件中最大重叠区间的大小。
对一个正整数 n ,如果 n 在数据文件中某行的两个正整数(假设为 A 和 B )之间,即 A<=n<=B 或 A>=n>=B ,则 n 属于该行;如果 n 同时属于行 i 和 j ,则 i 和 j 有重叠区间;重叠区间的大小是同时属于行 i 和 j 的整数个数。
例如,行( 10 20 )和( 12 25 )的重叠区间为 [12 20] ,其大小为 9 ;行( 20 10 )和( 12 18 )的重叠区间为 [10 12] ,其大小为 3 ;行 (20 10) 和( 20 30 )的重叠区间大小为 1 。
输入数据:程序读入已被命名为 input.txt 的输入数据文本文件,该文件的行数在 1 到 1,000,000 之间,每行有用一个空格分隔的 2 个正整数,这 2 个正整数的大小次序随机,每个数都在 1 和 2^32-1 之间。(为便于调试,您可下载测试 input.txt 文件,实际运行时我们会使用不同内容的输入文件。)
输出数据:在标准输出上打印出输入数据文件中最大重叠区间的大小,如果所有行都没有重叠区间,则输出 0 。
评分标准:程序输出结果必须正确,内存使用必须不超过 256MB ,程序的执行时间越快越好。

<pre>#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <ctime>

using namespace std;

struct number_pair {
unsigned long num1;
unsigned long num2;
unsigned long lineindex;
};

unsigned long get_area(number_pair *pair1, number_pair *pair2, number_pair *area)
{
unsigned long areasize = 0;

unsigned long pair1_1 = __min(pair1->num1, pair1->num2);
unsigned long pair1_2 = __max(pair1->num1, pair1->num2);

unsigned long pair2_1 = __min(pair2->num1, pair2->num2);
unsigned long pair2_2 = __max(pair2->num1, pair2->num2);

do
{
if ( pair1_1 > pair2_2 || pair2_1 > pair1_2 )
{
break;
}

if ( pair1_1 < pair2_1 )
{
if ( pair1_2 < pair2_2 )
{
areasize = pair1_2 - pair2_1 + 1;
area->num1 = pair2_1;
area->num2 = pair1_2;
}
else
{
areasize = pair2_2 - pair2_1 + 1;
area->num1 = pair2_1;
area->num2 = pair2_2;
}
}
else
{
if ( pair1_2 > pair2_2 )
{
areasize = pair2_2 - pair1_1 + 1;
area->num1 = pair1_1;
area->num2 = pair2_2;
}
else
{
areasize = pair1_2 - pair1_1 + 1;
area->num1 = pair1_1;
area->num2 = pair1_2;
}
}
} while( false );

return areasize;
}

int main()
{
bool breturn = false;
do
{
cout << "\n";
cout << "\n请选择下列一项后回车:\n";
cout << " 1、生成测试数据文件input.txt(在当前目录生成,如果存在,将覆盖)\n";
cout << " 2、运行测试程序。(输入数据为当前目录下的input.txt文件)\n";
cout << " 3、退出。\n";
cout << "请选择:";


int sel = 0;
cin >> sel;

switch ( sel )
{
case 1:
{
bool bMakeSuccess = false;
FILE *fp = fopen("input.txt", "w+");
if ( fp != NULL )
{
unsigned long linecount = 0;
cout << "\n请输入行数(1~~~1,000,000): ";
cin >> linecount;

char szbuffer[1024] = "\0";
srand( (unsigned)time( NULL ) );
for( unsigned long i = 0; i < linecount; ++i )
fprintf(fp, "%ld %ld\n", (unsigned int)rand(), (unsigned int)rand());

fclose(fp);

bMakeSuccess = true;
}

cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
if ( bMakeSuccess )
{
cout << "\n测试数据文件input.txt生成成功!\n";
}
else
{
cout << "\n测试数据文件input.txt生成失败!\n";
}
cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
break;
}
case 2:
{
unsigned long arysize = 1000000;
number_pair *pnumber_pair = new number_pair[arysize];
unsigned long cursize = 0;

bool bMakeSuccess = false;
unsigned long maxareasize = 0;
unsigned long tempareasize = 0;
unsigned long line1 = 0;
unsigned long line2 = 0;
unsigned long lineindex = 0;
number_pair area, temparea;

FILE *fp = fopen("input.txt", "r");
if ( fp != NULL )
{
if ( pnumber_pair == NULL )
{
bMakeSuccess = false;
}
else
{
char szbuffer[1024] = "\0";
do
{
if ( fgets(szbuffer, 1023, fp) == NULL )
{
break;
}
++lineindex;

sscanf(szbuffer, "%ld %ld\n", &pnumber_pair[cursize].num1, &pnumber_pair[cursize].num2);

pnumber_pair[cursize].lineindex = lineindex;

if ( (__max(pnumber_pair[cursize].num1, pnumber_pair[cursize].num2) -
__min(pnumber_pair[cursize].num1, pnumber_pair[cursize].num2)) <= maxareasize )
{
continue;
}

for ( unsigned long i = 0; i < cursize; ++i )
{
tempareasize = get_area(&pnumber_pair[i], &pnumber_pair[cursize], &temparea);
if ( tempareasize > maxareasize )
{
maxareasize = tempareasize;

line1 = i;
line2 = cursize;

area = temparea;
}
}

++cursize;
} while( cursize < arysize );
}

fclose(fp);

bMakeSuccess = true;
}

cout << "\n*****************************************************************\n";
if ( bMakeSuccess )
{
if ( maxareasize < 1 )
{
cout << "最大重叠区间的大小是:0\n";
}
else
{
cout << "\n最大重叠区间[" << area.num1 << " " << area.num2 << "]的大小是:" << maxareasize << "\n"
<< "由第 [" << pnumber_pair[line1].lineindex << "] 行 ("
<< pnumber_pair[line1].num1 << " " << pnumber_pair[line1].num2 << ") 和第 ["
<< pnumber_pair[line2].lineindex << "] 行 ("
<< pnumber_pair[line2].num1 << " " << pnumber_pair[line2].num2 << ") 得到。\n";
}
}
else
{
cout << "\n文件格式错误或文件input.txt不存在!\n";
}
cout << "\n*****************************************************************\n\n\n";

if ( pnumber_pair != NULL )
{
delete []pnumber_pair;
pnumber_pair = NULL;
}

break;
}
case 3:
{
breturn = true;
break;
}
default:
{
cout << "\n您输入有误, 请输入1---3之间的数。\n";
break;
}
}

if ( breturn )
{
break;
}
} while( 1 );

return 1;
}</pre>
General2005年百度之星程序设计大赛试题初赛题目一 Pin
onlinewan3-Nov-08 18:47
onlinewan3-Nov-08 18:47 
General实现在Word中查找指定内容,将其替换为指定图片 Pin
onlinewan23-Oct-08 15:12
onlinewan23-Oct-08 15:12 
General实现在Excel中查找指定内容,将其替换为指定图片 Pin
onlinewan23-Oct-08 15:04
onlinewan23-Oct-08 15:04 
General【某公司C++笔试题】 [modified] Pin
onlinewan12-Oct-08 22:57
onlinewan12-Oct-08 22:57 
General四道微软面试算法题 [modified] Pin
onlinewan12-Oct-08 16:28
onlinewan12-Oct-08 16:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.