1. 程式人生 > >CSU 1656: Paper of FlyBrother 1657: Ways 1658: IQ of XUEXX’s descendants 1659: Graph Center

CSU 1656: Paper of FlyBrother 1657: Ways 1658: IQ of XUEXX’s descendants 1659: Graph Center

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace
std; #define LS 2*i #define RS 2*i+1 #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 100005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 LL wa[N],wb[N],wsf[N],wv[N],sa[N]; LL rank1[N],height[N],s[N],a[N]; char
str[N],str1[N],str2[N]; //sa:字典序中排第i位的起始位置在str中第sa[i] //rank:就是str第i個位置的字尾是在字典序排第幾 //height:字典序排i和i-1的字尾的最長公共字首 LL cmp(LL *r,LL a,LL b,LL k) { return r[a]==r[b]&&r[a+k]==r[b+k]; } void getsa(LL *r,LL *sa,LL n,LL m)//n要包含末尾新增的0 { LL i,j,p,*x=wa,*y=wb,*t; for(i=0; i<m; i++) wsf[i]=0; for
(i=0; i<n; i++) wsf[x[i]=r[i]]++; for(i=1; i<m; i++) wsf[i]+=wsf[i-1]; for(i=n-1; i>=0; i--) sa[--wsf[x[i]]]=i; p=1; j=1; for(; p<n; j*=2,m=p) { for(p=0,i=n-j; i<n; i++) y[p++]=i; for(i=0; i<n; i++) if(sa[i]>=j) y[p++]=sa[i]-j; for(i=0; i<n; i++) wv[i]=x[y[i]]; for(i=0; i<m; i++) wsf[i]=0; for(i=0; i<n; i++) wsf[wv[i]]++; for(i=1; i<m; i++) wsf[i]+=wsf[i-1]; for(i=n-1; i>=0; i--) sa[--wsf[wv[i]]]=y[i]; t=x; x=y; y=t; x[sa[0]]=0; for(p=1,i=1; i<n; i++) x[sa[i]]=cmp(y,sa[i-1],sa[i],j)? p-1:p++; } } void getheight(LL *r,LL n)//n不儲存最後的0 { LL i,j,k=0; for(i=1; i<=n; i++) rank1[sa[i]]=i; for(i=0; i<n; i++) { if(k) k--; else k=0; j=sa[rank1[i]-1]; while(r[i+k]==r[j+k]) k++; height[rank1[i]]=k; } } LL t,ans,n,m; int main() { LL i,j,k,len; W(~scanf("%s",str)) { len = strlen(str); UP(i,0,len-1) s[i]=str[i]; s[len] = 0; getsa(s,sa,len+1,300); getheight(s,len); ans = (1+len)*len/2; UP(i,2,len) ans-=height[i]; printf("%lld\n",ans); } }
#include <iostream> 
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
using namespace std;
int a[1010][1010][2], f[4][2] = {0,1,1,0,0,-1,-1,0};
int vis[1010][1010], n;
int dp[1010][1010][2][2];
struct node
{
	int x, y;
}s, e;
int bfs()
{
	memset(vis, 0, sizeof(vis));
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	queue<node>q;
	s.x=1, s.y=1;
	if(a[1][1][0]<=a[1][1][1])
	{
		 dp[1][1][0][0] = a[1][1][0];
		 dp[1][1][0][1] = a[1][1][1];
	}
	else 
	{
		dp[1][1][1][0] = a[1][1][0];
		dp[1][1][1][1] = a[1][1][1];
	}
	vis[1][1]=1, q.push(s);
	while(!q.empty())
	{
		s=q.front(), q.pop();
		for(int i=0; i<4; i++)
		{
			e.x = s.x+f[i][0];
			e.y = s.y+f[i][1];
			if(e.x<1||e.x>n||e.y<1||e.y>n) continue;
			for(int k=0; k<2; k++)
			{
				int n2 = dp[s.x][s.y][k][0]+a[e.x][e.y][0];
				int n5 = dp[s.x][s.y][k][1]+a[e.x][e.y][1];
				if(n2<=n5 && dp[e.x][e.y][0][0]>n2)
				{
					dp[e.x][e.y][0][0] = n2;
					dp[e.x][e.y][0][1] = n5;
					if(!vis[e.x][e.y]) 
					{
						vis[e.x][e.y]=1, q.push(e);
					}
				}
				else if(n2>n5 && dp[e.x][e.y][1][1]>n5)
				{
					dp[e.x][e.y][1][0] = n2;
					dp[e.x][e.y][1][1] = n5;
					if(!vis[e.x][e.y])
					{
						vis[e.x][e.y]=1, q.push(e);
					}
				}
			}
		}
	}
	return min(dp[n][n][0][0], dp[n][n][1][1]);
}
int main()
{
	while(~scanf("%d", &n))
	{
		int x;
		for(int i=1; i<=n; i++)
		{
			for(int j=1; j<=n; j++)
			{
				scanf("%d", &x);
				int num2=0, num5=0;
				while(x%2==0) num2++, x/=2;
				while(x%5==0) num5++, x/=5;
				a[i][j][0] = num2;
				a[i][j][1] = num5;
			}
		}
		printf("%d\n", bfs());
	}
	return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long LL;
LL block[2][2];///儲存矩陣
LL tblock[2][2];
LL x,y;

void mul1(LL p)
{
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
            tblock[i][j] = 0;
            for(int k=0; k<2; k++)
                tblock[i][j] = (tblock[i][j] + block[i][k] * block[k][j]) % p;///1 1 = 10 * 0 1 + 11 * 11
        }
    }

    for(int i=0; i<2; i++)
        for(int j=0; j<2; j++)
           block[i][j] = tblock[i][j];
}

void mul2(LL p)
{
    LL ans = 0;
    LL t1,t2;
    t2 = block[0][1] * x % p + block[1][1] * y % p;
    t1 = block[0][0] * x % p + block[1][0] * y % p;
    x = t1 % p;
    y = t2 % p;
}

int main()
{
    int t;
    scanf("%d",&t);
    for(int cas = 1; cas <= t; cas++){
        LL a,b,p,n;
        scanf("%lld %lld %lld %lld %lld %lld",&x,&y,&a,&b,&p,&n);
        block[0][0] = 0;
        block[0][1] = a;
        block[1][0] = 1;
        block[1][1] = b;
        LL ans = 0;
        while(n){
            if(n & 1) mul2(p);
            mul1(p);
            n = n >> 1;
        }
        printf("Case #%d: %lld\n",cas,y);
    }
    return 0;
}
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <list>
#include <algorithm>
#include <climits>
using namespace std;

#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 200005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
const int mod = 1e9+7;
const int L = 10005;
struct Edges
{
    int x,y,w,next;
} e[L<<2];

int head[L],n,m;
int dis[L];
int vis[L];
int cnt[L],hash[L],ss[L];
int s[L];
void init()
{
    memset(e,-1,sizeof(e));
    memset(head,-1,sizeof(head));
}
void AddEdge(int x,int y,int w,int k)
{
    e[k].x = x,e[k].y = y,e[k].w = w,e[k].next = head[x],head[x] = k;
}
int relax(int u,int v,int c)
{
    if(dis[v]>dis[u]+c)
    {
        dis[v] = dis[u]+c;
        return 1;
    }
    return 0;
}

int SPFA(int src)
{
    int i;
    memset(vis,0,sizeof(vis));
    for(int i = 0; i<=n; i++)
        dis[i] = INF;
    dis[src] = 0;
    queue<int> Q;
    Q.push(src);
    vis[src] = 1;
    while(!Q.empty())
    {
        int u,v;
        u = Q.front();
        Q.pop();
        vis[u] = 0;
        for(i = head[u]; i!=-1; i=e[i].next)
        {
            v = e[i].y;
            if(relax(u,v,e[i].w)==1 && !vis[v])
            {
                Q.push(v);
                vis[v] = 1;
            }
        }
    }
    int maxn = -1;
    for(i = 1; i<=n; i++)
        maxn = max(maxn,dis[i]);
    return maxn;
}

int ans[L],tot,p[N];
int main()
{
    int t,u,v,i,j,k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        init();
        for(i = 0; i<2*m; i+=2)
        {
            scanf("%d%d",&u,&v);
            AddEdge(u,v,1,i);
            AddEdge(v,u,1,i+1);
        }
        int minn = INF;
        for(i = 1; i<=n; i++)
        {
            p[i] = SPFA(i);
            minn = min(p[i],minn);
        }
        tot = 0;
        for(i = 1; i<=n; i++)
        {
            if(p[i]==minn)
                ans[tot++] = i;
        }
        printf("%d\n",tot);
        for(i = 0; i<tot; i++)
        {
            if(i)
                printf(" ");
            printf("%d",ans[i]);
        }
        printf("\n");
    }

    return 0;
}

相關推薦

CSU 1656: Paper of FlyBrother 1657: Ways 1658: IQ of XUEXXs descendants 1659: Graph Center

#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #

CSU1656: Paper of FlyBrother(後綴數組)

++ click csu -s tor string 個數 subst problem Description FlyBrother is a superman, therefore he is always bus

[LeetCode] 349 Intersection of Two Arrays & 350 Intersection of Two Arrays II

記錄 rip arr 要求 intersect unique pub push sorted 這兩道題都是求兩個數組之間的重復元素,因此把它們放在一起。 原題地址: 349 Intersection of Two Arrays :https://leetcode.com

上傳文件報錯:Warning: POST Content-Length of 9443117 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

The lin clas php 但是 exce 小文件 情況 lan 只需在php.ini中設置: upload_max_filesize = 1000M; post_max_size = 1000M;還有一種情況就是小文件可以上傳成功,但是大文件上傳,$_FILES

LeetCode - X of a Kind in a Deck of Cards

In a deck of cards, each card has an integer written on it. Return true if and only if you can choose X >= 2 such that it is possible to split the e

Thoughts on the Application of Radar Technology to the Improvement of Street Light System

Abstract: Street lights are everywhere in people’s daily lives. But street lights can sometimes cause problems for people. First of all, long-term

Warning: POST Content-Length of 16767309 bytes exceeds the limit of 8388608 bytes in Unknown on line

使用xampp和WordPress,上傳新主題時報錯。 錯誤資訊: Warning: POST Content-Length of 16767309 bytes exceeds the limit of 8388608 bytes in Unknown on line&n

LeetCode-914.X of a Kind in a Deck of Cards(C++實現)

一、問題描述 In a deck of cards, each card has an integer written on it. Return true if and only if you can choose X >= 2 such that it is possible to

SANER 2018 論文閱讀- Dissection of a Bug Dataset: Anatomy of 395 Patches from Defects4J

Foreword This blog aims at explaining the SANER 2018 paper - “Dissection of a Bug Dataset: Anatomy of 395 Patches from Defects4J”.

914. X of a Kind in a Deck of Cards

In a deck of cards, each card has an integer written on it. Return true if and only if you can choos

LeetCode周賽#104 Q1 X of a Kind in a Deck of Cards (列舉)

問題描述 914. X of a Kind in a Deck of Cards In a deck of cards, each card has an integer written on it. Return true if and only if you c

Leetcode_Array --914. X of a Kind in a Deck of Cards [easy]

In a deck of cards, each card has an integer written on it. 在一副撲克牌中,每張牌上都寫了一個整數 Return true if and only if you can choose X >= 2

【python3】leetcode 914. X of a Kind in a Deck of Cards (easy)

 914. X of a Kind in a Deck of Cards (easy) In a deck of cards, each card has an integer written on it. Return true if and o

POST Content-Length of 65077906 bytes exceeds the limit of 52428800 bytes in Unknown on line 0

PHP上傳時,當上傳檔案大小超過php.ini中配置閾值時,會出現上面警告,從$_FILES中無法取到上傳的檔案資訊。 解決辦法 ① 開啟php.ini,修改如下兩行: # 上傳檔案的最大值 upload_max_filesize = 100M # post提交時最大資料大小

leetcode 914. X of a Kind in a Deck of Cards

題目 一摞牌,每張牌上寫了一個整數,如果能找到一個大於等於2的數X,把牌分成1或多組滿足下列條件: 每組有X張牌 每組裡的每張牌上寫得數字都是一樣的 Example 1: Input: [1,2,3,4,4,3,2,1] Output: true Expl

specific word count(index of) specific word count (index of )

specific word count (index of )   <script type="text/javascript"> var str="Hello world!" document.write(str.indexOf("Hello") + "<

Cuisine of early farmers revealed by analysis of proteins in pottery from Çatalhöyük

An international team led by researchers from the Max Planck Institute for the Science of Human History, the Freie Universität Berlin and the University o

Code of ethics doesn't influence decisions of software developers

"We applauded the decision to update the ACM code of ethics, but wanted to know whether it would actually make a difference," says Emerson Murphy-Hill, co

Death of a massive star and birth of compact neutron star binary

The research was led by graduate student Kishalay De and is described in a paper appearing in the October 12 issue of the journal Science. The work was do

A Critique of the User Interface and Experience of VSCO

However, even though a major problem of VSCO’s platform is having too simple of a platform, the editing page does a good job of incorporating learnability,