标签:
1 #include<stdio.h> 2 int fun(int a,int b){ 3 int ans=1; 4 while(b){ 5 if(b&1)ans*=a; 6 a*=a; 7 b>>=1; 8 } 9 return ans; 10 } 11 int main(){ 12 int m,n; 13 while(~scanf("%d%d",&m,&n))printf("%d\n",fun(m,n)); 14 return 0; 15 }
邻接表:
1 #include<stdio.h> 2 #include<string.h> 3 char head[100100],cnt; 4 struct s 5 { 6 int u,v,w; 7 int next; 8 }edge[100010]; 9 void add(int u,int v,int w) 10 { 11 edge[cnt].u=u; 12 edge[cnt].v=v; 13 edge[cnt].w=w; 14 edge[cnt].next=head[u]; 15 head[u]=cnt++; 16 } 17 int main() 18 { 19 int n; 20 while(scanf("%d",&n)!=EOF) 21 { 22 int i; 23 cnt=0; 24 memset(head,‘-‘,sizeof(head)); 25 for(int i=0;i<100;i++)printf("%c ",head[i]); 26 for(i=0;i<n;i++) 27 { 28 int u,v,w; 29 scanf("%d%d%d",&u,&v,&w); 30 add(u,v,w); 31 } 32 int u; 33 scanf("%d",&u); 34 for(i=head[u];i!=-1;i=edge[i].next) 35 { 36 int v=edge[i].v; 37 int w=edge[i].w; 38 } 39 } 40 return 0; 41 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4706217.html