NOIP2015_day1
来源:互联网 发布:淘宝京科御发骗局 编辑:程序博客网 时间:2024/06/03 19:08
第一题模拟矩阵填数
#include<cstdio>#include<iostream>#include<cmath>#include<cstdlib>#include<cstring>#include<algorithm>#define LL long long#define INF 1000000000#define eps 1e-10#define sqr(x) (x)*(x)#define pa pair<int,int>#define cyc(i,x,y) for(i=(x);i<=(y);i++)#define cy2(i,x,y) for(i=(x);i>=(y);i--)using namespace std;inline 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=10*x+ch-'0';ch=getchar();} return x*f;}int n,a[40][40];int main(){// freopen("input.in","r",stdin);// freopen("output.out","w",stdout); cin>>n;n=n*2-1; int i=1,j=(1+n)/2,num=1; a[i][j]=1; while(num<n*n) { if(i==1&&j!=n) {a[i=n][j=j+1]=++num;}else if(j==n&&i!=1){a[i=i-1][j=1]=++num;}else if(i==1&&j==n) a[i=i+1][j]=++num;else if(a[i-1][j+1]) a[i=i+1][j]=++num;else a[i=i-1][j=j+1]=++num; } cyc(i,1,n) { cyc(j,1,n-1) cout<<a[i][j]<<' '; cout<<a[i][n]<<endl; } return 0;}
第二题强联通缩点*(会爆栈嘛?so sad)
#include<cstdio>#include<iostream>#include<cmath>#include<cstdlib>#include<cstring>#include<algorithm>#define LL long long#define INF 1000000000#define eps 1e-10#define sqr(x) (x)*(x)#define pa pair<int,int>#define cyc(i,x,y) for(int i=(x);i<=(y);i++)#define cy2(i,x,y) for(i=(x);i>=(y);i--)using namespace std;inline 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=10*x+ch-'0';ch=getchar();} return x*f;}#define N 200010int tot,ti,n,top,cnt;int head[N],e[N],next[N];int scc[N],sta[N],s[N],low[N],dfn[N];void add(int x,int y){e[++tot]=y;next[tot]=head[x];head[x]=tot;}void dfs(int x){ int y; low[x]=dfn[x]=++ti;sta[++top]=x; for(int i=head[x];i;i=next[i]) if(!dfn[y=e[i]]) { dfs(y); low[x]=min(low[x],low[y]); }else if(!scc[y]) low[x]=min(low[x],dfn[y]); if(low[x]==dfn[x]) { cnt++; while(1) { scc[y=sta[top--]]=cnt;s[cnt]++; if(y==x) break; } }}void tarjan(){cyc(i,1,n)if(!dfn[i])dfs(i);}int main(){// freopen("input.in","r",stdin);// freopen("output.out","w",stdout); int x; cin>>n; cyc(i,1,n) { cin>>x; add(i,x); } tarjan(); int ans=INF; cyc(i,1,cnt) { if(s[i]==1) continue; ans=min(ans,s[i]); } cout<<ans<<endl; return 0;}
第三题 斗地主是个坑三百行代码不愿意再写一遍了
况且考场上只会骗分
so sad!
0 0
- NOIP2015_day1
- 最大公约数与最小公倍数
- Xpath语法介绍及Web网页元素属性查找
- Introduction-to-React-JS
- 求x, 使x的平方为一个各位数字互不相同的9位数
- 斯坦福大学-机器学习20讲-第二讲
- NOIP2015_day1
- 除以路径中所有数 时间戳+LCA+路径压缩 2D
- webservice生成客户端代码时,出现的问题
- 技术人员为什么要写博客
- PowerShell实战 第二回 管理AD用户对象
- Android DrawerLayout和NavigationView 的使用方法
- Linux 入门常用命令
- JavaWeb中的监听器
- 大量excel文件批量转换成印刷pdf文件:两个小表格自动合成一页