-
个人简介
Welcome to Phigros
(其实是臀萌
Phira 密码:73ac
something nice come from Luogu
很好玩的东西! Touch/Click to play!
你该不会真运行了吧......
Good luck!
书写 https://help.luogu.com.cn/rules/academic/solution-standard
优先队列(小根/大根堆)
template<typename T,unsigned int siz,bool(*cmp)(T x,T y)> class pri_queue{ private: int len=0; T heap[siz]; void swap(T &a,T &b){T tmp=a;a=b;b=tmp;} void push_up(int x){ while(x>1&&cmp(heap[x>>1],heap[x])){ swap(heap[x>>1],heap[x]); x>>=1; } } void push_down(int x){ int p=1,l,r; while(true){ l=x<<1,r=(x<<1)+1; if(l<=len&&cmp(heap[x],heap[l]))p=l; if(r<=len&&cmp(heap[p],heap[r]))p=r; if(x==p)return; else{ swap(heap[x],heap[p]); x=p; } } } public: T* begin(){return heap+1;} T* end(){return heap+len+1;} int size(){return len;} bool empty(){return len==0;} T top(){return heap[1];} void push(T val){ heap[++len]=val; push_up(len); } void pop(){ heap[1]=heap[len--]; push_down(1); } }; bool cmp(int a,int b){return a<b;}//小根堆
树结构(先序访问?)
#include<cstdio> #include<vector> #include<cstring> using namespace std; struct node{ int id,len=0; node *fa,*sn[1000]; }tr[1000]; int n,m,x,y; node *ptr; bool is_head[1000]; void dfs(int now){ printf("%d",tr[now].id); for(int i=1;i<=tr[now].len;i++){ dfs(tr[now].sn[i]->id); } return; } int main(){ memset(is_head,true,sizeof(is_head)); scanf("%d",&n); for(int i=1;i<=n;i++){ tr[i].id=i; scanf("%d%d",&x,&m); ptr=&tr[x]; //sz=tr[x].sn->size(); for(int j=1;j<=m;j++){ scanf("%d",&y); tr[y].fa=ptr; tr[x].sn[++tr[x].len]=&tr[y]; is_head[y]=false; } } for(int i=1;i<=n;i++){ if(is_head[i]){ dfs(i); printf("\n"); } } } /* 5 1 2 2 3 2 0 3 2 4 5 4 0 5 0 */ /* 6 1 3 2 3 4 2 1 5 3 0 4 0 5 1 6 6 0 */ /* 样例1 [1] / \ [2] [3] / \ [4] [5] 样例2 [1] / | \ [2][3] [4] | [5] | [6] */
没学过树......学完链表后突发奇想用指针链出一棵树......
高精度计算 除法不知道咋写......先放着吧。
#include<cstdio> #include<iostream> #include<cstring> #define ll long long using namespace std; struct bignum{ int len,val[5000];//从第len位存到第1位 void print(){ for(int i=len;i>=1;i--)printf("%d",val[i]); } void input(){ char str[5005]; scanf("%s",str); len=strlen(str); for(int i=0;i<len;i++)val[len-i]=str[i]-'0'; } void cpy(ll num){ if(num==0){ len=1; return; } len=0; while(num>0){ val[++len]=num%10; num/=10; } } void cpy(bignum num){ for(int i=1;i<=num.len;i++)val[i]=num.val[i]; len=num.len; } }; bignum tobignum(ll num){ bignum res; res.cpy(0); if(num==0){ res.len=1; return res; } res.len=0; while(num>0){ res.val[++res.len]=num%10; num/=10; } return res; } void print(bignum n){ n.print(); } bool operator==(const bignum& a,const bignum& b){ if(a.len!=b.len)return false; for(int i=1;i<=a.len;i++){ if(a.val[i]!=b.val[i])return false; } return true; } bool operator==(const bignum& a,const ll& x){ bignum b=tobignum(x); return a==b; } bool operator==(const ll& x,const bignum& b){ bignum a=tobignum(x); return a==b; } bool operator!=(const bignum& a,const bignum& b){ return !(a==b); } bool operator!=(const bignum& a,const ll& x){ bignum b=tobignum(x); return a!=b; } bool operator!=(const ll& x,const bignum& b){ bignum a=tobignum(x); return a!=b; } bool operator<(const bignum& a,const bignum& b){ if(a.len>b.len)return false; if(a.len<b.len)return true; for(int i=a.len;i>=1;i--){ if(a.val[i]>b.val[i])return false; if(a.val[i]<b.val[i])return true; } return false; } bool operator<(const bignum& a,const ll& x){ bignum b=tobignum(x); return a<b; } bool operator<(const ll& x,const bignum& b){ bignum a=tobignum(x); return a<b; } bool operator>(const bignum& a,const bignum& b){ if(a.len>b.len)return true; if(a.len<b.len)return false; for(int i=a.len;i>=1;i--){ if(a.val[i]>b.val[i])return true; if(a.val[i]<b.val[i])return false; } return false; } bool operator>(const bignum& a,const ll& x){ bignum b=tobignum(x); return a>b; } bool operator>(const ll& x,const bignum& b){ bignum a=tobignum(x); return a>b; } bool operator>=(const bignum& a,const bignum& b){ return !(a<b); } bool operator>=(const bignum& a,const ll& x){ bignum b=tobignum(x); return a>=b; } bool operator>=(const ll& x,const bignum& b){ bignum a=tobignum(x); return a>=b; } bool operator<=(const bignum& a,const bignum& b){ return !(a>b); } bool operator<=(const bignum& a,const ll& x){ bignum b=tobignum(x); return a<=b; } bool operator<=(const ll& x,const bignum& b){ bignum a=tobignum(x); return a<=b; } bignum operator+(const bignum& a,const bignum& b){ bignum c; c.cpy(0); bool add=0; for(int i=1;i<=max(a.len,b.len);i++){ c.val[i]=(a.val[i]+b.val[i]+add)%10; add=(a.val[i]+b.val[i]>9); } c.len=max(a.len,b.len); if(add)c.val[++c.len]=1; return c; } bignum operator+(const bignum& a,const ll& x){ bignum b=tobignum(x); return a+b; } bignum operator+(const ll& x,const bignum& b){ bignum a=tobignum(x); return a+b; } bignum operator*(const bignum& a,const bignum& b){ bignum c; c.cpy(0); int add; for(int i=1;i<=a.len;i++){ bignum t; t.cpy(0),add=0; for(int j=1;j<=b.len;j++){ t.val[j]=(a.val[i]*b.val[j]+add)%10; add=(a.val[i]*b.val[j]+add)/10; } t.len=b.len; if(add>0)t.val[++t.len]=add; for(int j=t.len;j>=1;j--)t.val[j+i-1]=t.val[j]; for(int j=1;j<i;j++)t.val[j]=0; t.len+=i-1; c=c+t; } return c; } bignum operator*(const bignum& a,const ll& x){ bignum b=tobignum(x); return a*b; } bignum operator*(const ll& x,const bignum& b){ bignum a=tobignum(x); return a*b; } bignum operator-(const bignum& a,const bignum& b){ bignum c; bool d[5005]; memset(d,false,sizeof(d)); c.cpy(0); for(int i=1;i<=a.len;i++){ if(a.val[i]-d[i]>=b.val[i]){ c.val[i]=a.val[i]-b.val[i]-d[i]; }else{ d[i+1]=true; c.val[i]=a.val[i]+10-d[i]-b.val[i]; } } for(int i=1;i<=a.len;i++){ if(c.val[i]>0)c.len=i; } return c; } bignum operator-(const bignum& a,const ll& x){ bignum b=tobignum(x); return a-b; } bignum operator-(const ll& x,const bignum& b){ bignum a=tobignum(x); return a-b; } bignum a,b; int main(){ }
搜索算法可视化
#include<cstdio> #include<iostream> #include<cstring> #include<Windows.h> #include<algorithm> #include<stack> #include<queue> using namespace std; const int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1}; int r,c,sx,sy,tick=60; bool vis[1005][1005]; bool check(){ for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ if(!vis[i][j])return false; } } return true; } void print(){ int filled=0; for(int i=1;i<=c;i++)printf("—"); printf("\n"); for(int i=1;i<=r;i++){ printf("|"); for(int j=1;j<=c;j++){ if(vis[i][j]){ printf("█"); filled++; }else printf(" "); } printf("|\n"); } for(int i=1;i<=c;i++)printf("—"); printf("\n"); Sleep(1000/tick); system("cls"); return; } bool bound(int x,int y){ return x>=1&&x<=r&&y>=1&&y<=c; } void dfs(){ memset(vis,false,sizeof(vis)); stack<pair<int,int> > p; p.push(make_pair(sx,sy)); while(!p.empty()){ if(!check())print(); pair<int,int> t=p.top(); vis[t.first][t.second]=true; p.pop(); for(int i=0;i<4;i++){ int nx=t.first+dx[i]; int ny=t.second+dy[i]; if(bound(nx,ny)&&!vis[nx][ny]){ p.push(make_pair(nx,ny)); } } } return; } void bfs(){ memset(vis,false,sizeof(vis)); queue<pair<int,int> > p; p.push(make_pair(sx,sy)); vis[sx][sy]=true; while(!p.empty()){ if(!check())print(); pair<int,int> f=p.front(); p.pop(); for(int i=0;i<4;i++){ int nx=f.first+dx[i]; int ny=f.second+dy[i]; if(bound(nx,ny)&&!vis[nx][ny]){ p.push(make_pair(nx,ny)); vis[nx][ny]=true; } } } } void error(){ cerr<<"Error!\n"; Sleep(1500); system("cls"); } int main(){ int ch; while(true){ printf("---搜索算法可视化--- by 2024tysc0454\n"); printf("行数:%d 列数:%d\n初始位置:%d,%d\n帧率:%d\n",r,c,sx,sy,tick); printf("输入选项:\n[1]DFS\n[2]BFS\n[3]退出\n[4]更改行列\n[5]调整帧率\n"); scanf("%d",&ch); if(ch==1)dfs(); else if(ch==2)bfs(); else if(ch==3)break; else if(ch==4){ printf("输入行数和列数:\n"); scanf("%d%d",&r,&c); if(r>1000||c>1000){ r=0,c=0; error(); continue; } printf("输入起点位置:\n"); scanf("%d%d",&sx,&sy); if(!bound(sx,sy)){ r=0,c=0; sx=0,sy=0; error(); continue; } }else if(ch==5){ printf("输入帧率:\n"); scanf("%d",&tick); if(tick==0){ tick=60; error(); } } system("cls"); } return 0; } /* 更新日志: 2025-3-7 程序完成! 2025-3-8 修复了BFS过慢的问题,加入帧率。 */
世界盒子(v 0.1 测试版)
#include<bits/stdc++.h> #include<cstdlib> #include<ctime> #include<Windows.h> using namespace std; #define INF 0x7fffff #define SIZE 3000 #define tot_item 5 #define sight 4 #define MIN 1 #define MAX 100 #define OP_SIZE 9 const int item_ap[tot_item]={0,0,0,15,20}; const int item_hp[tot_item]={-1,-1,5,10,25}; const string item_name[tot_item]={"//","始","土","木","石"}; pair<int,int> choose; int choose2; vector<pair<int,int> > game_op(OP_SIZE); void setColor(int color) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color); } struct listen{ bool isKeyPressed(int keyCode) { return(GetAsyncKeyState(keyCode)&0x8000)!=0; } pair<int,int> listening(vector<pair<int,int> > op){ while(true){ for(int i=0;i<op.size();i++){ bool f1,f2=true; f1=isKeyPressed(op.at(i).first); if(op.at(i).second!=0)f2=isKeyPressed(op.at(i).second); if(f1&&f2)return op.at(i); } } } }lis; struct item{ int id,ap,hp; string name; }item_list[100]; struct player{ int x,y,ap,hp; vector<item> own; }; //bound 0,start 1,dirt 2,tree 3,rock 4 struct new_game{ short map[SIZE+2][SIZE+2]; player p; void game_init(){ srand(static_cast<unsigned int>(time(0))); p.x=p.y=1; p.ap=10; p.hp=100; p.own.clear(); for(int i=0;i<=SIZE+1;i++)map[i][0]=map[0][i]=map[i][SIZE+1]=map[SIZE+1][i]=0; for(int i=1;i<=SIZE;i++){ for(int j=1;j<=SIZE;j++){ int rd=rand()%(MAX-MIN+1)+MIN; if(rd<=56)map[i][j]=2; else if(rd<=56+22)map[i][j]=3; else if(rd<=56+22+22)map[i][j]=4; } } map[1][1]=1; } void print_sight(){ for(int i=p.x-sight;i<=p.x+sight;i++){ for(int j=p.y-sight;j<=p.y+sight;j++){ if(i<0||i>SIZE||j<0||j>SIZE)cout<<" "; else if(i==p.x&&j==p.y)cout<<"你"; else{ cout<<item_name[map[i][j]]; } } cout<<endl; } } void game(){ while(p.hp>0){ cout<<"位置:(x:"<<p.x<<",y:"<<p.y<<")"<<endl; cout<<"攻击:"<<p.ap<<" 血量:"<<p.hp<<endl; cout<<"物品栏:"; for(int i=0;i<p.own.size();i++)cout<<p.own[i].name<<' '; cout<<endl; print_sight(); cout<<endl; choose=lis.listening(game_op); if(choose==game_op[0]&&(map[p.x-1][p.y]==1||map[p.x-1][p.y]==2))p.x--; if(choose==game_op[1]&&(map[p.x][p.y-1]==1||map[p.x][p.y-1]==2))p.y--; if(choose==game_op[2]&&(map[p.x+1][p.y]==1||map[p.x+1][p.y]==2))p.x++; if(choose==game_op[3]&&(map[p.x][p.y+1]==1||map[p.x][p.y+1]==2))p.y++; if(choose==game_op[4]&&(map[p.x-1][p.y]==3||map[p.x-1][p.y]==4)){ p.own.push_back(item_list[map[p.x-1][p.y]]); map[p.x-1][p.y]=2; } if(choose==game_op[5]&&(map[p.x][p.y-1]==3||map[p.x][p.y-1]==4)){ p.own.push_back(item_list[map[p.x][p.y-1]]); map[p.x][p.y-1]=2; } if(choose==game_op[6]&&(map[p.x+1][p.y]==3||map[p.x+1][p.y]==4)){ p.own.push_back(item_list[map[p.x+1][p.y]]); map[p.x+1][p.y]=2; } if(choose==game_op[7]&&(map[p.x][p.y+1]==3||map[p.x][p.y+1]==4)){ p.own.push_back(item_list[map[p.x][p.y+1]]); map[p.x][p.y+1]=2; } if(choose==game_op[8])return; system("cls"); Sleep(200); } } }g; void item_init(){ for(int i=0;i<tot_item;i++){ item_list[i].id=i; item_list[i].ap=item_ap[i]; item_list[i].hp=item_hp[i]; item_list[i].name=item_name[i]; } } void opset_init(){ game_op[0].first='W',game_op[0].second=0; game_op[1].first='A',game_op[1].second=0; game_op[2].first='S',game_op[2].second=0; game_op[3].first='D',game_op[3].second=0; game_op[4].first='W',game_op[4].second=VK_SHIFT; game_op[5].first='A',game_op[5].second=VK_SHIFT; game_op[6].first='S',game_op[6].second=VK_SHIFT; game_op[7].first='D',game_op[7].second=VK_SHIFT; game_op[8].first=VK_ESCAPE,game_op[8].second=0; } //红色 FOREGROUND_RED 绿色 FOREGROUND_GREEN 蓝色 FOREGROUND_BLUE int main(){ item_init(); opset_init(); while(true){ setColor(FOREGROUND_RED|FOREGROUND_GREEN); // 设置字体颜色为红色 cout<<"本游戏由2024tysc0454制作,请勿抄袭QAQ!"<<endl<<"世界盒子 v 0.1"<<endl; setColor(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); cout<<"[1] 开始游戏"<<endl<<"[2] 退出"<<endl; cin>>choose2; if(choose2==2)exit(0); system("cls"); cout<<"正在生成世界..."<<endl; Sleep(3000); g.game_init(); cout<<"开始游戏!"<<endl; Sleep(2000); system("cls"); g.game(); system("cls"); } } /*更新记录 v0.1.1游戏制作 v1.1.1 2025-2-21 Update 加入了按键监听,以后移动就可以直接按按键了\o/\o/\o/ */
扫雷(v0.1 测试版)
//by 2024tysc0454 请勿抄袭 #include<bits/stdc++.h> #include<cstdlib> #include<ctime> using namespace std; #define MIN 1 #define MAX 100 int seed,cnt=0,b[11][11]; bool a[11][11]; int randint(int min,int max){ return rand()%(max-min+1)+min; } int main(){ srand(static_cast<unsigned int>(time(0))); cin>>seed; for(int i=1;i<=9;i++){ for(int j=1;j<=9;j++){ int r=randint(MIN,MAX); if(r<=13||88<r){ a[i][j]=1; cnt++; }else{ a[i][j]=0; } } } cout<<"0~8:已展示格记号\n█:未展示格记号\n▲:标记记号"<<endl<<endl; system("pause"); while(cnt!=0){ system("cls"); cout<<"剩余数量:"<<cnt<<endl; int s; for(int i=1;i<=9;i++){ for(int j=1;j<=9;j++){ if(b[i][j]==0){ cout<<"█"; }else if(b[i][j]==2){ cout<<' '<<a[i][j-1]+a[i][j+1]+a[i-1][j]+a[i+1][j]+a[i-1][j-1]+a[i-1][j+1]+a[i+1][j+1]+a[i+1][j-1]; }else{ cout<<"▲"; } } cout<<endl; } cout<<"[1]翻开格"<<endl<<"[2]标记/取消标记格"<<endl; cin>>s; int x,y; cin>>x>>y; if(s==1){ if(a[x][y]){ system("cls"); cout<<"GAME OVER"; for(int i=1;i<=9;i++){ for(int j=1;j<=9;j++){ if(a[i][j])cout<<"●"; else cout<<" "; } cout<<endl; } return 0; }else{ b[x][y]=2; } }else if(s==2){ if(b[x][y]==1){ b[x][y]=0; if(a[x][y]==1) cnt++; }else if(b[x][y]==0){ b[x][y]=1; if(a[x][y]==1) cnt--; } } } cout<<"YOU WIN!"; return 0; }
-
最近活动
- 第四届 TYCPC 程序设计大赛(重现补题赛) IOI
- D班-第六周周末练习题 作业
- D班——倍增算法 作业
- D班——动规加强(区间环形DP/多维DP/差值DP) 作业
- D班-第三周周末练习题 作业
- D班——区间DP之区间合并 作业
- D班——区间DP之区间分割 作业
- D班——搜索算法作业题 作业
- 2024预备班复活赛 OI
- 【oiClass公益赛】2025CSP-J模拟赛#15 OI
- 【oiClass公益赛】2025CSP-J模拟赛#14 OI
- 【oiClass公益赛】2025CSP-J模拟赛#13 OI
- 【oiClass公益赛】2025CSP-J模拟赛#12 OI
- 【oiClass公益赛】2025CSP-J模拟赛#11 OI
- 【oiClass公益赛】2025CSP-J模拟赛#10 OI
- 【oiClass公益赛】2025CSP-J模拟赛#09 OI
- 【oiClass公益赛】2025CSP-J模拟赛#08 OI
- 【oiClass公益赛】2025CSP-J模拟赛#07 OI
- 【oiClass公益赛】2025CSP-J模拟赛#06 OI
- 【oiClass公益赛】2025CSP-J模拟赛#05 OI
- 【oiClass公益赛】2025CSP-J模拟赛#04 OI
- 【oiClass公益赛】2025CSP-J模拟赛#03 OI
- 【oiClass公益赛】2025CSP-J模拟赛#02 OI
- 【oiClass公益赛】2025CSP-J模拟赛#01 OI
- 结营测试改题 IOI
- D班——背包动态规划2 作业
- D班——背包动态规划1 作业
- D班——二维动规之最长公共子序列 作业
- D班——二维线性动态规划规 作业
- D班——线性动规之子序列问题 作业
- D班——线性动态规划基础 作业
- D班——二分搜索 作业
- D班——二分算法 作业
- D班——队列 作业
- D班——广度优先搜索 作业
- 2024小六冬令营《队列》 作业
- 铁外信息学作业-CD班(25年1月-循环结构、数组) 作业
- 2024预备——期末测试改题 IOI
- 2024预备--深度优先搜索算法2 作业
- 2024预备--深度优先搜索算法 作业
- 2024预备--递归算法加强 作业
- 2024预备--递归算法入门 作业
- 2024预备班--阶段测试5 OI
- 2024预备--第13周周中练习 作业
- 2024预备班11月阶段测试(订正) IOI
- 2024预备--栈 作业
- 2024预备--差分前缀和 作业
- 2024预备--贪心算法 作业
- 2024预备--枚举算法 作业
- 2024预备--模拟算法 作业
- 2024预备--第八周加练题单 作业
- 2024预备--指针&结构体&排序 作业
- 2024预备班10月阶段测试 OI
- 2024预备--位运算 作业
- 2024预备--进制转换 作业
- 2024预备--函数 作业
- 2024预备--第四周周中习题 作业
- 2024预备班阶段测试1 OI
- D班——差值DP/双指针 作业
- 2024预备--字符、字符串加强练习 作业
- 2024预备--习题订正 作业
- 2024预备--二维数组基础 作业
- 2024oiClass入门组周赛计划#18 IOI
- 2024oiClass入门组周赛计划#17 IOI
- 2024oiClass入门组周赛计划#16 IOI
- 2024oiClass入门组周赛计划#15 IOI
- 2024oiClass入门组周赛计划#14 IOI
- 2024oiClass入门组周赛计划#13 IOI
- 2024oiClass入门组周赛计划#12 IOI
- 2024oiClass入门组周赛计划#11 IOI
- 2024oiClass入门组周赛计划#10 IOI
- 2024oiClass入门组周赛计划#09 IOI
- 2024新苗-递推算法基础 作业
- 2024新苗--排序算法基础 作业
- 2024新苗--字符、字符数组、字符串 作业
- 2024新苗--数组标记的应用 作业
- 2024新苗--一维数组基础 作业
- 2024新苗--多重循环 作业
- 2024新苗班阶段测试2 OI
- 2024新苗--while2 作业
- 2024新苗--循环语句(while语句1) 作业
- 2024新苗--数据的在线处理 作业
- 2024新苗班阶段测试一(下午班) OI
- 2024新苗--枚举和筛选 作业
- 2024新苗--循环语句(for语句1) 作业
- 2024新苗--选择结构 作业
- 2024新苗--表达式 作业
- 2024新苗--C++程序结构 作业
-
Stat
-
Rating