无聊的倒序 模拟
#include<bits/stdc++.h> using namespace std; int n,ans,x; int main(){ scanf("%d",&n); for(int i = 1; i <= n; i++){ scanf("%d",&x); ans = 0; while(x){ ans =ans*10 + x % 10; x /= 10; } printf("%d\n",ans); } return 0; }
节约的alice 贪心
#include<iostream> #include<cstdio> using namespace std; int n,k,a[10]; int main(){ scanf("%d",&n); a[++k] = n/100; n = n % 100; a[++k] = n/50; n = n % 50; a[++k] = n/20; n = n % 20; a[++k] = n / 10; n = n % 10; a[++k] = n / 5; n = n % 5; a[++k] = n; for(int i = k; i >=1; i--) printf("%d ",a[i]); return 0; }
新扫雷游戏 递推
#include<bits/stdc++.h> using namespace std; int a[100005],b[100005],ans; void f(int n){ int fl = 0; for(int i = 3; i <= n; i++){ b[i] = a[i - 1] - b[i - 1] - b[i - 2]; if(b[i] > 1 || b[i] < 0){ fl = 1;break; } } if(fl == 0 && b[n - 1] + b[n] == a[n]) ans++; } int t,n; int main(){ scanf("%d",&t); while(t--){ scanf("%d",&n); ans = 0; for(int i = 1; i <= n; i++){ scanf("%d",&a[i]); } //如果是0或者2,则要不方案为1要么方案为0 if(a[1] == 0) { b[1] = 0; b[2] = 0; f(n); } else if(a[1] == 2){ b[1] = 1; b[2] = 1; f(n); } else if(a[1] == 1){//如果第一个数是1,则最多两种方法,分类判断是否成立 b[1] = 0; b[2] = 1; f(n); b[1] = 1; b[2] = 0; f(n); } printf("%d\n",ans); } return 0; }
最短路转bfs问题
#include<bits/stdc++.h> using namespace std; int n,m,t,x,y,l,hd[10000005],cnt,dis[10000005],vis[10000005]; queue<int> q; struct Node{ int to,nxt; }edge[40000005]; void add(int u,int v){ cnt++; edge[cnt].to = v; edge[cnt].nxt = hd[u]; hd[u] = cnt; } void bfs(){ dis[1] = 0; vis[1] = 1; q.push(1); while(!q.empty()){ int u = q.front(); q.pop(); // cout<<u<<endl; for(int i = hd[u]; i; i = edge[i].nxt){ int v = edge[i].to; if(vis[v]) continue; dis[v] = dis[u] + 1; // cout<<v<<" "<<dis[v]<<endl; if(v == t){ printf("%d\n",dis[v]); return; } vis[v] = 1; q.push(v); } // cout<<endl; } return ; } int k = 0; int main(){ scanf("%d%d%d",&n,&m,&t); for(int i = 1; i <= m; i++){ scanf("%d%d%d",&x,&y,&l); if(l == 2) { add(x, n + (++k)); add(n + k, y); add(y, n + k); add(n + k, x); }else{ add(x,y); add(y,x); } } // for(int j = hd[6] ; j ; j = edge[j].nxt) // cout<<edge[j].to<<endl; bfs(); return 0; }