ACM上一些常见问题解答

 

FAQ:
(Remember to use Ctrl+F)
 

从今天起,我会把在joj和bbs上回答的问题总结后贴出来。暂时先写这么多,

会不停的更新,希望新手问问题之前先查一查.

也希望大家能够补充,我会注明出处的!

1
ASK:
1001 的循环怎么结束啊?

REP:
while(cin>>a) 读到文件结束时(EOF)会自动结束
{
}

2
ASK:
不知道什么会 runtime error

#include
int main()
{int i,j,n,m,s,a[10][10];
while(scanf("%d %d",&m,&n),m&&n)
{for(i=0;ifor(j=0;jscanf("%d",&a[i][j]);
s=a[0][0];
for(i=0;ifor(j=0;jif(sprintf("%d",s);}
}

REP:

题目数据可能会比较大,所以应该写成a[103][103]

3
ASK:
2003第一组sample output第三行, 第三列,是1/8,为什么不是0.13而是0.12???

REP:
根据编译器的不同,可能会把0.13算成0.1299999...
所以成了0.12,所以不用理会他,只要算法没问题就行


ASK:
为什么会wa啊
REP:
wjiang:
出现wa,那就是你有些地方没有考虑到,或者是代码有错误(正好这个错误在题目给你的测试数据中没有表现出来),你就要仔细的读题目,别落下什么有用的信息,再仔细的读你的代码,然后自己写一些测试数据,特别是边缘的数据来测试。我也经常碰上这样的问题,特别的闹心,不过通过了又会特别的高兴。

5
ASK:
能控制输入数据小数位数吗

REP:/*下面两个得同时用才行,其中x代表小数位数*/
cout.setf(ios::fixed);
cout.precision(x);

6
ASK:
我怎么总是出现 compile error?

REP:
Siyee:
近来发现joj上来了很多新手,with many compilation errors,所以
提醒一个问题:

submit页面中需要“粘贴”源程序,而不是直接写。可以事先用任何一个
C++ IDE(集成开发环境,比如vc, c++builder等)。在用IDE时,需要创建
控制台程序(console,而不是windows程序)。控制台程序一般只包含一个
文件:*.cpp,其中的格式大致为:

#include....
...

int main(void)
{
...
}

在IDE中编译调试通过后,觉得没问题了,再复制粘贴到submit页面中进行
提交。可以通过点击runtime error和compilation error来查看具体信息。
 

点击compilation error,可以看到提示信息。
机器不同、操作系统不同、编译器不同、编译选项不同都可能造成
编译结果不同。joj的编译选项比较严格,既不允许有error,也不
允许有warning。


7
ASK:
当程序wa了之后,我发现我根本没有好的调试方法,最多是插入一些输出
语句看看中间变量的情况,然后对着屏幕发呆,如果题目要求的数据量不大的
话,我甚至打出所有结果,然后挨个查,最后发现往往是某个临界值错了
这样就耗了一两小时。。。
有什么更好的方法呢?

REP:

evilll :

我都是用f5,f10和f11来配合.


uhunter
vc中有debug功能,你可以设置断点,可以单步调试,比较方便
F9:在光标处插入断点
F11:运行到下一个断点处
F10:执行一条语句
你可以试试看

可以看执行过程中变量值的变化来判断程序是否朝着自己预期的方向执行

而devcpp的调试功能15:07 2011-7-1似乎不如vc方便

...
果然, 按着断点里面的语句走,变量值变化的很清晰。
以前一进入debug环境头就大,因为一弄就全是汇编语言
就一直用土方法,挨了那么多道题。。。。


8:
ASK:
相同的题目是否每次提交时的测试数据都相同?
有时提交同样的代码,第一次 超时 第二次就好了 是否只是服务器的速度的原因
还有没有别的原因,比例说 每次提交时的测试数据不一样?

REP:
walkoncloud :

题目所给的最大时间,通常都比标准程序所需要的时间大得多得多。如果你的程序刚好不
超时通过,就说明的你的程序运行时间还是太多,还需要修改。

一个不超时的程序(哪怕是错误的)编译运行是很快的。但如果一个同学把超时的程序反
复提交,其他同学就会感觉服务器很慢。

服务器运行在一个Linux之上,进程运行的时间受那个时刻系统负载大小、用户多少、运行
的其它任务等因素影响,不可能每次都时间一样的。

当然,更快些的服务器会好些,但需要好多money。

9
ASK:
JUDGE TYPE Special 是什么意思?

REP:

使用程序而不是简单的文件比较来判断对错。
skywind:如不限次序的输出
lzr:同一测试数据可能有多个输出测试,与任意相同即可

10
ASK:
用什么可以看程序的执行时间呀?

REP:
加代码的话加这些:
#include
#include
using namespace std;
int main()
{
time_t begin,end;
begin=clock();
//your code(此处输入自己的代码!)
end=clock();
cout<<"runtime: "<}

11
ASK:
能在DOS下编译C 程序吗?

REP:
Siyee
没学过编译,有些概念容易混淆。简单地说
编译:把源程序“翻译”成目标程序
编译器:执行编译任务的程序
IDE:Integrated Development Environment,集成开发环境,“集成”是指将
编辑、编译和调试“集成”在一起,可以通过统一的界面完成。

例如:
Visual Studio是IDE的集合,VB,VC是IDE
gcc是C语言编译器
g++是C++语言预处理器(将C++转换成C,再调用gcc)
gdb是调试器,只要可执行文件中有调试信息即可,不仅限于C/C++


一个简单的IDE:用notepad写C代码,然后用gcc编译,用gdb调试!

无论是什么“器”都是程序而已。

DOS、Linux、Windows是OS(操作系统),即执行程序的平台,能否在某平台下
编译C程序取决于该平台下是否有C程序的编译器,事实上都有。

编译器属于系统软件,任何OS都应当具有编译器。

12
ASK:
数组开的不够大,为什么错误不是re,而是wa呢?

REP:
Siyee
1. re = runtime error, 言外之意是送入CPU的指令发生异常
2. 数组越界 = 访问了数组外的空间
3. 数组外的空间可以是指令空间,也可以是数据空间
4. 指令被更改不一定会发生re,因为更改后的指令很可能也是有效的
5. 因此,数组越界 != re
6. 这也是为什么不允许用gets的原因


12
ASK:
请问如何买代码?

REP:
首先进入题目的status里面,然后看下面列举的状态里那个代码你想买,
点击go,然后点击代码前面的运行号就行了!

13
ASK:
请问cout.setf有什么用?

REP:
实数输出默认是浮点数的一般格式,最多显示六位有效位,setprecision(n)规定总有效位数,但小数最末的0是不显示的.setiosflags(ios::fixed)或者直接fixed实现定点输出,小数点后默认恒定6位有效数字,setprecision(n)规定小数点后有效位数.小数最末的0显示! setiosflags(ios::scientific)或者直接scientific实现指数输出,小数点后默认恒定6位有效数字.setprecision(n)规定小数点后有效位数.
 例:
double d=12345.67890123456789;
       cout<<<<<<输出 12345.7
12345.6789
12345.6789012346
12345.67890
1.23457e+004
1.2345678901e+004
 

标程:
NOTE:

许多标程都是收集来的,在这里仅供大家参考,我只是希望大家不要仅仅通过提交标程来增加ac题目数量,至少你要会比葫芦画瓢,其次是理解,以至写出更好的代码:)

 

1001:

 

C标程

#include

int main()

{

       double in,sum=0;

       while( scanf("%lf",&in) != EOF )

              sum+=in;

       printf("%.15g\n",sum);

       return 0;

}

 

C++标程

#include

using namespace std;

int main()

{

       double in,sum=0;

       while( cin>>in )

              sum+=in;

       cout.precision(15);

       cout<

       return 0;

}

 

1009:

C标程

#include

#include

#define N 1000

int main()

{

       int i,j,k,n;

       int flag=0;

 

       while(scanf("%d",&n),n){

              if(flag) printf("\n");

              else flag=1;

 

              for(i=0;i

                     printf("%c",'a'+i%26);

 

              printf("\n");

              for(j=0;j

                     for(k=0;k

                            putchar(32);

                     printf("%c\n",'a'+i%26);

 

              }

 

              for(j=0;j

                     printf("%c",'a'+i%26);

                     i++;

              }

              printf("\n");

 

       }

       return 0;

}

 

1021

标程

#include

char ans[1000101];

int main()

{    

       int i,sum,temp;

       for(i=1;i<=1000000;i++){

 

              if(!ans[i])  printf("%d\n",i);

 

              temp=sum=i;

              while(temp!=0){

                     sum=sum+temp%10;

                     temp/=10;

              }

              ans[sum]=1;

       }

       return 0;

}

 

1024

标程

#include

int Array[21][21][21];

 

int w(int a,int b,int c)

{

       if(a<=0||b<=0||c<=0) return 1;

       else if(a>20||b>20||c>20) return w(20,20,20);

       else if(Array[a][b][c]) return Array[a][b][c];

       else if((a

       else return Array[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);

}

 

int main()

{

       int a,b,c;

       while(scanf("%d%d%d",&a,&b,&c),a!=-1||b!=-1||c!=-1)

              printf("w(%d, %d, %d) = %d\n",a,b,c,w(a,b,c));

       return 0;

}

 

1175

标程

 

组合数学公式:

#includeint main(){         int m,n,k,p;         while(scanf("%d%d",&m,&n)&&m){                 double d=1.0;                 k=m;p=n;                 if(n>m/2) n=m-n;                 while(n){d=d*m/n;m--;n--;}                 printf("Binom(%d, %d) = %.0lf\n",k,p,d);}}

动态规划:

#includevoid main(){         int i,j,a[35][35];         for(i=0;i<31;i++)         {                 a[0][i]=1;                 a[i][0]=1;         }         for(i=1;i<31;i++)                 for(j=1;j<31;j++)                 {                          a[i][j]=a[i-1][j]+a[i-1][j-1];                          if(i==j)a[i][j]=1;                 }                 cin>>i>>j;                 while(i||j)                 {                          cout<<"Binom("< 

TOC
Introduction
Getting Started
Exchanging Source Codes
Contacting Other JOJers
Enjoying Contests
Ranklist
Frequently Asked Questions
Introduction
Welcome to Jilin University Online Judge System (JOJ). It's one of the best online judge systems in China and the training ground for the ACMers in Jilin University . JOJ now provides up to 1000 problems and still collects more.

Back To Top

Getting Started
Register
Before you become a jojer, you have to register for an account. Click on the Register on the main menu then fill in a short form, you are done.

Choose and solve your first problem
There are two ways for you to choose a problem.

Click on Problems on the main menu, and choose one problem from the problem list. The list can be sorted by the problem ID (default), the ratio, the number of accepted runs or the number of total submits. Simply click on the ID, Ratio, Accepted, or Submit on the head of problem list. (You can start by 1000).

If you want to choose a specific problem, you can also use the search problems function on the main menu.

After choosing your problem, you should first write your code (in Pascal or C++) locally on your own computer and tested it using your favorite IDE. When you are sure of the correctness of your code, submit your source code to the judge by clicking submit.

Status after submitting
After submitting your code, you will be redirected to the status page in 3 seconds where you will see the status in the following format:

RID
 PID
 Author
 Status
 Code
 Lang
 Date & Time
 
73010
 1000
 Lionheart
 Accepted
(0.00s 414K +0+0 )
 184
Bytes
 C++
 2004-06-28 13:56:48
 

RID: The ID for the submit. By clicking it, you will have the access to the source code of the submit, but you have to first pay for it if it's not submitted by you. (See More Details)

PID: The problem ID.

Author: The submitter ID. After you've clicked it, the author's status's page will appear.

Code: The length of the code.

Lang: The language used in the submitted source code.

Status: The status indicating the time your program has run, the memory your program has consumed, the Jpoints you have gained and whether your code is accepted by the judge or not. It will be one of the following:

Type of Wrong Messages
 Meaning
 
Wrong Answer
 Your program makes wrong answer. That's probably caused by wrong algorithm or misunderstanding of the problem.
 
Presentation Error
 The output format is wrong. You should read the output specification of the problem again and check the output part of your program.
 
Runtime Error
 It means your program halted down during runtime. Possibly it's caused by dividing by zero or array outranging (invalid memory access).
 
Time Limit Exceeded
 It means the running time of your program exceeded the time limit of the problem. You should change another algorithm or make your program optimized.
 
Memory Limit Exceeded
 It means the memory consumed of your program exceeded the memory limit of the problem. You should change another algorithm or make your program optimized.
 
Output Too Much
 It means the output of your program is too much. Maybe it's caused by misunderstanding of the problem. Check if your program terminates?
 
Compilation Error
 That is a very stupid error. No matter what kind of IDE you are using, you should always use the standard C/C++ library (or reference).
 
Judge Error
 Maybe there is something wrong with the judge or the server. Please contact me as soon as possible.
 

You should fix your program according to the first 5 of above 6 wrong messages while it is me who is always responsible to the last wrong message, say JUDGE ERROR.

Besides, there are other accessory messages which also mark the status of the run of your program. Here they are:

Type of Other Messages
 Meaning
 
Accepted
 Congratulations! Your program has been accepted by the judge. You should then choose another program to solve.
 
Waiting
 It means the server is busy and the judge hasn't processed your request. You should wait for a while patiently. Remember do not submit your program again. The judge will process your program soon.
 
Compiling
 It means your program is being compiled on the server.
 
Compilation OK
 It means your program has just been compiled without errors and prepares to run.
 
Running
 It means your program is running on the server.
 

Back To Top

Source Code Exchanging
It's possible to buy other authors' source codes using Jpoints on JOJ.

Collecting Jpoints
Generally, Jpoints are collected when the judge has accepted your solution for a specific problem for the first time. You will also receive extra Jpoints, if you win a contest, some other people have bought your code, you are among the first five people who successful solved a specific problem or you are solving problem in numeric order.

Details:

You will receive X+Y Jpoints for each accepted submit, where X is the basic Jpoints and Y is the addition reward. X=10+T, if you are among the first five successful submitter to the problem, say you are the nth submitter, t = (5-n+1). If you successfully solved n problems consequently, y=min (10, n). While in Contest, X will equal to 30.

Pricing of a source code
The cost of a source code may vary due to the number of accepted runs for the problem. It can be calculated by the following formulas:

Cost (For the buyer) = MAX (100,200- 1.15^n), where n is the number of accepted submitters. Gain (For the owner) = cost * %3
Accessing to a source code
You may access to a source code by clicking its RID. If you want to view the code you have already purchased, simply click on the number indicating the number of Jpoints you have to open trade log. Note: you won't have to pay again for the same RID.

 

Closing/Reopening your source code
If you don't want other authors to see your code, you may close one or all of your source codes. Simply access to the code you want to close and click on “Close this source code” or “Close all source code”. Of course, source code can be reopened in this way too.

Please Note: all codes are open by defaults.

Back To Top

Contacting other JOJers
You can contact other JOJers using sender or Email. Sender is the messaging service provided by JOJ. Click on “Sender” on the author's status page will open the sender addressing to that author provided the author's sender hasn't been closed, while the name on author's status page is linked to the email address of the author.

Back To Top

Enjoying Contests
JOJ sometimes holds contests. You will find competing in contest is real fun.

Entering a contest
When the contest has started, you can join the contest by clicking on the Contest on the main menu.

Please Note:

You have to submit under contest system, namely, access problems directly from the CONTEST PAGE!!!
You can't purchase others' solution to the contest problem during contest.
Scoring
There are two components to a team's score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.

So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.

The winner is the team that solves the most problems. If teams tie for solving the most problems, then the winner is the team with the fewest penalty points.

Back To Top

Rank List
Wanna check out how well you and others are doing? Go to the Rank List.

Back To Top

Frequently Asked Questions
Q: I have successfully tested my source code on my PC, but I got a compiler error after submission. Why?

A: If you are using C++, you are experiencing compatibility problems of C++. Please change a compiler. G++ and VC.NET are strong recommended.

Q: What most probably caused “Runtime Error”?

A: You will get a “Runtime Error”, if you are trying to visit a pointer that points to an invalid address/ your array has overflowed/your program returned non-zero.

Q: How to control precision in C++?

A: cout.precision() can be used to control precision. Remember, if you want to use fixed numeric format. Add cout.setf(ios::fixed) to your code, because the scientific numeric format is the default of C++. Check out PID 1020.

Q: Why is gets() forbidden?

A: Gets() is a dangerous function. Please try using getline(), getchar() instead.

你可能感兴趣的:(暑假ACM训练)