Sketch:
For informatics contests, batting is an extremely important skill. It can use an inefficient but accurate program to validate our advanced algorithm program with a large amount of randomly generated data.
Simply put, in the course of the competition, I believe that everyone has experienced an amazing wa in the written program, but the small data of their own hand is okay, even if they are self-confident enough to think that they are the problem of Judge Ji. At this time, you can use pairing photos to make yourself aware of the reality of wa. We can write a very complex but absolutely correct violence. Then write a data generator according to the title code requirements, let the violence code and wa code run at the same time, and write a script to run and compare the results, to achieve "simple evaluation Ji". If the difference proves you are wa, then you can have a happy debug with the data
Of course, if you can't shoot it, don't doubt Judge. You definitely read the wrong question
Windows has been taking photos all over the world, but there are no good blog posts for Mac Os users, so today I will focus on how MAC users can take photos with programs.
Pre-preparation
Sublime Text
A brief introduction to Sublime Text, a lightweight text editor known for its clean and elegant interface
Download directly Official Web Download it
Simply configure Sublime Text
-
Click Tools->Build System->Build New System
-
Then enter a configuration: (Just paste the whole past directly)
{ "cmd": ["bash", "-c", "g++ '${file}' -std=c++11 -stdlib=libc++ -o '${file_path}/${file_base_name}'"], "file_regex": "^(..{FNXX==XXFN}*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++", "variants": [ { "name": "Run", "cmd": ["bash", "-c", "g++ '${file}' -std=c++11 -stdlib=libc++ -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"] } ] }
-
Then press and press Command+S to save, named C/C++.sublime-build, C/C++ whatever you want, but don't change the suffix name and save path, just default
The configuration file is saved under / Users / User Name / Library/Application Support/Sublime Text 3/Packages/User
-
Then you can write c/c++ code now, and when you're done, click Tools->Build System->C:C++.
Note that because the file name I just saved was C/C++, and/or was automatically replaced with: Yes, all C:C++ is the configuration file I just saved
-
After selecting the compiler, press Command+B, then select C:C++ - Run to run, next time press Command+B directly
Simulated Judger
For instance:
Given a natural number n (n<=100000), solve the sum of 1+2+3+...+n
test1.cpp requires a program to verify correctness
test2.cpp Violence Program
data.cpp Data Generator
compare.cpp Comparator
In this case, the program test2.cpp written by violence is the sum of violence running from 1 to n, calculated by longlong
The program test1.cpp that needs to be tested writes n * (n + 1) / 2, but uses the variable int
You can see that n explodes when it's a little bigger
Create a folder on your desktop and write out the following four programs, all in that folder
test1.cpp
#include<iostream> using namespace std; typedef long long ll; //Don't open longlong to see ancestors! int main(){ freopen("test.in","r",stdin); freopen("test1.out","w",stdout); int n; cin>>n; cout<<n * (n + 1) / 2<<endl; return 0; }
Notice that freopen writes test1's in and out, so don't write bad batches.
test2.cpp
#include<iostream> using namespace std; typedef long long ll; //Don't open longlong to see ancestors! int main(){ freopen("test.in","r",stdin); freopen("test2.out","w",stdout); int n; ll sum = 0; cin>>n; for(int i = 1; i <= n; ++i)sum += i; cout<<sum<<endl; return 0; }
compare.cpp
#include<cstdio> #include<cstdlib> #include<iostream> int main() { int tmp=0; for(int i=1;i<=10000;i++) { system("./data"); system("./test1"); system("./test2"); // if(i/100>tmp) {printf("-- %d --\n",i);tmp=i/100;} if(system("diff test1.out test2.out")) { printf("wrong in --> %d \n",i); break; } printf("process %d is correct\n",i); } return 0; }
data.cpp
#include<iostream> using namespace std; int main() { freopen("test.in","w",stdout); srand(time(0)); int a = rand() % 100000; cout<<a<<endl; return 0; }
After each program has been written, it needs to be compiled to produce an executable, and Sublime Text will be generated directly next to the original program
That's what happens when you're done (the last three are data storage that doesn't occur until you've taken one shot)
Now we need to use the MAC's own terminal, command + whitespace to wake up directly
#Learn a little about the linux commands you might use pwd #Indicates the current directory, that is, the path cd ... #Indicates a directory into... ./compare #Run compare program control + c # Stop running
After we open the terminal, we need to enter the folder to take photos. The first way is to open the folder, drag the name of the folder to the terminal, and then we can display the path of the folder, which can be accessed by using the cd command, or by downloading a super right-click app, the right-click folder can have a command to enter the terminal, and click and send
When you type. /compare, you start to take a photo. When you find an error, it looks like the following
Use control + c if you can't run and want to stop
Running data is placed in test.cpp and can be viewed directly
That's basically it. Detailed steps I might take time to record on Station B and temporarily cook first