zoukankan      html  css  js  c++  java
  • 快速幂及邻接表的一些小技巧

     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
    ",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 }
  • 相关阅读:
    1月28日 layout_list_item
    1月27日 listview_MyListAdapter
    1月26日 listviewxml
    1月25日 textview
    1月24日 人月神话3
    体温填报(三)
    体温填报(二)
    体温填报(一)
    家庭记账本(六)
    家庭记账本(五)
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4706217.html
Copyright © 2011-2022 走看看