目录(感觉有目录很了不起的样子)
一、代码
#pragma GCC optimize(2,3,"Ofast","inline")
#include<rturtle.h>
#include<utilapiset.h>
#include<conio.h>
#include<bits/stdc++.h>
#include<ctime>
#include<unordered_map>
#include<unordered_set>
#define Sleep(a) _sleep(a)
#define ll long long
#define reg register
using namespace std;
inline int int_read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-48;
ch=getchar();
}
return x*f;
}
inline string string_read(){
string x="";
char ch=getchar();
x=x+ch;
while(ch!=' '&&ch!='\n'){
ch=getchar();
x=x+ch;
}
return x;
}
inline char char_read(){
return getchar();
}
inline double double_read(){
int x=0,f=1;
double y=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while((ch>='0'&&ch<='9')||ch=='.'){
if(ch>='0'&&ch<='9'){
x=x*10+(ch-48);
}else{
break;
}
ch=getchar();
}
ch=getchar();
while(ch>='0'&&ch<='9'){
y=y*10+ch-48*1.0;
ch=getchar();
}
while(y>1){
y=y/10;
}
return (x+y)*f;
}
inline void circle(double a){
arc(a,360);
}
inline void get_help(){
system("start https://http://t.csdn.cn/HfXXZ/");
}
inline bool Prime(int num){
if(num<=1){
return false;
}
if(num==2||num==3){
return true;
}
if(num%6!=1&&num%6!=5){
return false;
}else{
return true;
}
}
inline random(int left,int right){
if(left>right){
return 0;
}
return time(0)%(right-left+1)+left;
}
inline void star(double line=400,double size=5,double x=0,double y=0,bool tutrle=true){
Color a[5]={RED,ORANGE,PURPLE,BLUE,GREEN};
setPenColor(RED);
if(tutrle==false){
hide();
}
penUp();
setPenSize(size);
setXY(x+(line*sin(18)/2),y-(line*cos(18))/2);
penDown();
setAngle(72);
fd(line);
for(int i=1;i<=4;i++){
setPenColor(a[i]);
rt(144);
fd(line);
}
penUp();
}
inline void tutrle_draw(bool game=0){
if(game==0){
setPenSize(1);
}
show();
penUp();
for(int i=1;i<=180;i++){
fd(200);
penDown();
drawPoint(getX(),getY());
if(game==1){
penUp();
}
rt(60);
fd(200);
rt(60);
fd(200);
rt(60);
fd(200);
rt(60);
fd(200);
rt(60);
fd(200);
rt(178);
}
}
inline void rainbow(double line=500,double x=getX(),double y=getY(),double size=40){
Color a[7]={RED,ORANGE,YELLOW,GREEN,CYAN,BLUE,PURPLE};
for(int i=0;i<=6;i++){
setPenSize(size);
setPenColor(a[i]);
penUp();
setX(x-size*i);
penDown();
arc(line,180);
line=line-size;
rt(180);
}
}
typedef struct Z{//ai+b
int a;
int b;
}Z;
typedef struct sound{
unsigned long s;
double l;
}sound;
#define l1 CLITERAL(sound){262,500}
#define l2 CLITERAL(sound){294,500}
#define l3 CLITERAL(sound){330,500}
#define l4 CLITERAL(sound){349,500}
#define l5 CLITERAL(sound){392,500}
#define l6 CLITERAL(sound){440,500}
#define l7 CLITERAL(sound){498,500}
#define n1 CLITERAL(sound){532,500}
#define n2 CLITERAL(sound){588,500}
#define n3 CLITERAL(sound){660,500}
#define n4 CLITERAL(sound){698,500}
#define n5 CLITERAL(sound){784,500}
#define n6 CLITERAL(sound){880,500}
#define n7 CLITERAL(sound){998,500}
#define h1 CLITERAL(sound){1046,500}
#define h2 CLITERAL(sound){1175,500}
#define h3 CLITERAL(sound){1319,500}
#define h4 CLITERAL(sound){1397,500}
#define h5 CLITERAL(sound){1568,500}
#define h6 CLITERAL(sound){1760,500}
#define h7 CLITERAL(sound){1976,500}
inline void play(sound a){
Beep(a.s,a.l);
}
template<class T>
class tree{
public:
struct tree_node{
T num;//存的值
list<tree_node*>child;//子节点
tree_node*father;//父节点
};
tree_node trunk;//根节点
tree_node*find(T x){//查找
if(x==trunk.num){
return &x;
}else{
return dfs(trunk,x);
}
}
inline void push(T nuum,tree_node*fatherr){//加入
list<tree_node*>_;
tree_node numm;
numm.child=_;
numm.num=nuum;
numm.father=fatherr;
fatherr->child.push_back(&numm);
}
inline void init(T key){
list<tree_node*>_;
trunk={key,_,NULL};
}
private:
inline tree_node*dfs(tree_node*x,T y){
if(x->child.empty()){
return NULL;
}
if(x.num==y){
return x;
}
else{
for(int i=0;i<x.child.size();i++){
if(dfs(x.child.front(),y)!=NULL){
return dfs(x.child.front());
}
x.child.push_back(x.child.front());
x.child.pop_front();
}
return NULL;
}
}
};
二、每段分析
①、 头文件
#include<rturtle.h>//非C++自带
#include<utilapiset.h>
#include<conio.h>
#include<bits/stdc++.h>
#include<ctime>
②、函数
1、circle()函数
void circle(double a){
arc(a,360);
}
2、get_help()函数
inline void get_help(){
system("start https://http://t.csdn.cn/HfXXZ/");
}
3、Prime()函数
bool Prime(int x){
if(x<=1){
return false;
}else{
for(int i=2;i*i<=x;i++){
if(x%i==0){
return false;
}
}
return true;
}
}
4、random()函数
inline int random(int left,int right){
if(left>right){
return 0;
}
return time(0)%(right-left+1)+left;
}
5、star()函数
inline void star(double line=400,double size=5,double x=0,double y=0,bool tutrle=true){
Color a[5]={RED,ORANGE,PURPLE,BLUE,GREEN};
setPenColor(RED);
if(tutrle==false){
hide();
}
penUp();
setPenSize(size);
setXY(x+(line*sin(18)/2),y-(line*cos(18))/2);
penDown();
setAngle(72);
fd(line);
for(int i=1;i<=4;i++){
setPenColor(a[i]);
rt(144);
fd(line);
}
penUp();
}
6、tutrle_draw()函数
inline void tutrle_draw(bool game=0){//无聊的小游戏
if(game==0){
setPenSize(1);
}
show();
penUp();
for(int i=1;i<=180;i++){
fd(200);
penDown();
drawPoint(getX(),getY());
if(game==1){
penUp();
}
rt(60);
fd(200);
rt(60);
fd(200);
rt(60);
fd(200);
rt(60);
fd(200);
rt(60);
fd(200);
rt(178);
}
}
7、rinbow()函数
inline void rainbow(double line=500,double x=getX(),double y=getY(),double size=40){
Color a[7]={RED,ORANGE,YELLOW,GREEN,CYAN,BLUE,PURPLE};
for(int i=0;i<=6;i++){
setPenSize(size);
setPenColor(a[i]);
penUp();
setX(x-size*i);
penDown();
arc(line,180);
line=line-size;
rt(180);
}
}
8、快读
inline int int_read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-48;
ch=getchar();
}
return x*f;
}
inline string string_read(){
string x="";
char ch=getchar();
x=x+ch;
while(ch!=' '&&ch!='\n'){
ch=getchar();
x=x+ch;
}
return x;
}
inline char char_read(){
return getchar();
}
inline double double_read(){
int x=0,f=1;
double y=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while((ch>='0'&&ch<='9')||ch=='.'){
if(ch>='0'&&ch<='9'){
x=x*10+(ch-48);
}else{
break;
}
ch=getchar();
}
ch=getchar();
while(ch>='0'&&ch<='9'){
y=y*10+ch-48*1.0;
ch=getchar();
}
while(y>1){
y=y/10;
}
return (x+y)*f;
}
③、其他
1、sound
typedef struct sound{
unsigned long s;
double l;
}sound;
#define l1 CLITERAL(sound){262,500}
#define l2 CLITERAL(sound){294,500}
#define l3 CLITERAL(sound){330,500}
#define l4 CLITERAL(sound){349,500}
#define l5 CLITERAL(sound){392,500}
#define l6 CLITERAL(sound){440,500}
#define l7 CLITERAL(sound){498,500}
#define n1 CLITERAL(sound){532,500}
#define n2 CLITERAL(sound){588,500}
#define n3 CLITERAL(sound){660,500}
#define n4 CLITERAL(sound){698,500}
#define n5 CLITERAL(sound){784,500}
#define n6 CLITERAL(sound){880,500}
#define n7 CLITERAL(sound){998,500}
#define h1 CLITERAL(sound){1046,500}
#define h2 CLITERAL(sound){1175,500}
#define h3 CLITERAL(sound){1319,500}
#define h4 CLITERAL(sound){1397,500}
#define h5 CLITERAL(sound){1568,500}
#define h6 CLITERAL(sound){1760,500}
#define h7 CLITERAL(sound){1976,500}
void play(sound a){
Beep(a.s,a.l);
}
注意:该部分参考洛谷博客
2、tree
没文化的去这里
template<class T>
class tree{
public:
struct tree_node{
T num;//存的值
list<tree_node*>child;//子节点
tree_node*father;//父节点
};
tree_node trunk;//根节点
tree_node*find(T x){//查找
if(x==trunk.num){
return &x;
}else{
return dfs(trunk,x);
}
}
inline void push(T nuum,tree_node*fatherr){//加入
list<tree_node*>_;
tree_node numm;
numm.child=_;
numm.num=nuum;
numm.father=fatherr;
fatherr->child.push_back(&numm);
}
inline void init(T key){
list<tree_node*>_;
trunk={key,_,NULL};
}
private:
inline tree_node*dfs(tree_node*x,T y){
if(x->child.empty()){
return NULL;
}
if(x.num==y){
return x;
}
else{
for(int i=0;i<x.child.size();i++){
if(dfs(x.child.front(),y)!=NULL){
return dfs(x.child.front());
}
x.child.push_back(x.child.front());
x.child.pop_front();
}
return NULL;
}
}
};
三、安装及其使用
①、安装
点立即下载并且打开
全选后复制
打开你的编译器(我用的是小熊猫C++),找到文件夹,搜索include
随便点一个(只要是叫include的都行)
按右键粘贴,然使用后无论如何一直点继续
最后就可以开始使用啦
②、使用
打开编译器,新建一个cpp文件
注意事项
如果编译时报错,需在工具-->编译选项-->编译时加入一下命令:插入代码 -std=c++14(我就没报错)
如果还不行,请将代码中的
#pragma GCC optimize(2,3,"Ofast","inline")
删去,参考手动开上O2优化(c++) 和openwrt GCC 编译错误:error: #pragma GCC diagnostic not allowed inside functions
画五角星☆
#include<game.h>//引用这个库
using namespace std;
int main(){
initWorld(1000,1000);//创建一个世界
star();//调用
waitClick();//等待按鼠标
closeWorld();//关闭世界
return 0;
}
运行结果:
画圆○
#include<game.h>//引用这个库
using namespace std;
int main(){
initWorld(1000,1000);//创建一个世界
setSpeed(1000);
circle(200);//调用
waitClick();//等待按鼠标
closeWorld();//关闭世界
return 0;
}
运行结果:
画彩虹
#include<game.h>//引用这个库
using namespace std;
int main(){
initWorld(1000,1000);//创建一个世界
setSpeed(1000);
rainbow();//调用
waitClick();//等待按鼠标
closeWorld();//关闭世界
return 0;
}
运行结果:
快读函数
#include<game.h>//引用这个库
using namespace std;
int main(){
int a;
a=int_read();//调用
cout<<a;
return 0;
}
运行结果:
#include<game.h>//引用这个库
using namespace std;
int main(){
double a;
a=double_read();//调用
cout<<a;
return 0;
}
运行结果:
#include<game.h>//引用这个库
using namespace std;
int main(){
char a;
a=char_read();//调用
cout<<a;
return 0;
}
运行结果:
#include<game.h>//引用这个库
using namespace std;
int main(){
string a;
a=string_read();//调用
cout<<a;
return 0;
}
运行结果: