2016 "Baidu Star"-Preliminary round (Astar round2a)

Source: Internet
Author: User

title Link:http://acm.hdu.edu.cn/search.php?field=problem&key=2016%26quot%3B%B0%D9%B6%C8%D6%AE%D0%C7% 26quot%3b+-+%b3%f5%c8%fc%a3%a8astar+round2a%a3%a9&source=1&searchmode=source

1001:

Matrix Fast Power

#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<vector>using namespacestd;Const intN = 5e5+ -, M = 1e2+Ten, mod =1000000007, INF =1e9;typedefLong Longll;structMatix {ll arr[m][m];}; ll X,m,k,c;    Matix Mul (Matix A,matix b,ll hang, ll lie) {Matix ans; memset (Ans.arr,0,sizeof(Ans.arr));  for(intI=1; i<=hang;i++) {       for(intt=1; t<=lie;t++)         for(intj=1; j<=lie;j++) {Ans.arr[i][t]+ = (a.arr[i][j]*b.arr[j][t]); Ans.arr[i][t]%=K; }    }    returnans;} Matix Pow (Matix Ans,matix a,ll x) { while(x) {if(x&1) Ans=mul (Ans,a,2,2); A=mul (A,a,2,2); X/=2; }    returnans;}intMain () {ll x, y, Z; intt,cas=1; scanf ("%d",&T);  while(t--) {scanf ("%i64d%i64d%i64d%i64d",&x,&m,&k,&c);        Matix fir,sec;        Matix now; now.arr[1][1]=x; now.arr[1][2]=x; memset (Fir.arr,0,sizeof(Fir.arr)); sec.arr[1][1]=Ten; sec.arr[1][2]=0; sec.arr[2][1]=1; sec.arr[2][2]=1; fir.arr[1][1]=1; fir.arr[2][2]=1; Fir=pow (fir,sec,m-1); Fir=mul (Now,fir,2,2); printf ("Case #%d:\n", cas++); if(fir.arr[1][1]==c) puts ("Yes"); ElsePuts"No"); }    return 0;}
View Code

1005:

Pretreatment +dfs

Preprocessing each length, the answer of each length

Then find out the answer to the corresponding length Dfs

#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<vector>using namespacestd;Const intN = 1e3+ -, M = 1e6+Ten, mod =1000000007, INF =1e9;typedefLong LongLl;ll len[n],dp[n],l,r;ll dfs (ll x) {if(x<=0)return 0; if(x<=2)returnx; if(x==3)return 2; ll ans=0; intpos = Upper_bound (len+1, len+ +, x)-Len-1; if(len[pos]==x)returnDp[pos]; if(x-len[pos]==1)returndp[pos]+1; LL ret= dp[pos]+1; ll Shen= x-len[pos]-1; returnRet+shen-dp[pos] + DFS (len[pos)-shen);}intMain () {dp[1] =1; len[1] =1;  for(intI=2; i<= A; i++) {Len[i]= len[i-1]*2+1; }     for(intI=2; i<= A; i++) {Dp[i]= dp[i-1] +1+ len[i-1]-dp[i-1]; }    intT; scanf ("%d",&T);  while(t--) {scanf ("%i64d%i64d",&l,&s); printf ("%i64d\n", DFS (R)-dfs (l1)); }    return 0;}
View Code

1006

Priority queue

First, according to the topology, the penetration is 0 of the press in, the priority position of the large front ...

#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<vector>using namespacestd;Const intN = 5e5+ -, M = 1e6+Ten, mod =1000000007, INF =1e9;typedefLong Longll;intK,c,x,d[n],n,m,vis[n];vector<int>G[N];intAns[n];intMain () {intT; intCAS =1; scanf ("%d",&T);  while(t--) {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) g[i].clear ();  for(intI=1; i<=n;i++) Vis[i] =0, d[i] =0;  for(intI=1; i<=m;i++) {            intb; scanf ("%d%d",&a,&b);            G[a].push_back (b); D[B]++; } priority_queue<int>Q;  for(intI=1; i<=n;i++) {            if(d[i]==0) Q.push (i); }        intCNT =0 ;  while(!Q.empty ()) {            intK =Q.top (); ans[++CNT] =K; //cout<<k<<endl;Q.pop ();  for(intI=0; I<g[k].size (); i++) {D[g[k][i]]--; if(d[g[k][i]]==0&&!Vis[g[k][i]])                    {Q.push (g[k][i]); Vis[g[k][i]]=1; }            }        }        intMi =1e9; LL AA=0;  for(intI=1; i<=cnt;i++) {mi=min (ans[i],mi); AA= AA +mi; } printf ("%i64d\n", AA); }    return 0;}
View Code

2016 "Baidu Star"-Preliminary round (Astar round2a)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.