牛客每日练习----Journey,Bazinga,平分游戏

我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。                                      ----喻言

 链接:https://ac.nowcoder.com/acm/problem/15338
来源:牛客网

题目描述

Mr.Frog wants to travel all over the country, and as we all know the country consists of N cities and M directed roads connecting these cities. The cities are numbered from 1 to N. The roads are numbered from 1 to M, the ith road connects the city Ui to Vi which means Mr.Frog can move to city Vi from city Ui.

Mr.Frog wants to travel all cities, and he can choose a city to start his trip casually and choose a city to end his trip casually. In order to avoid the boredom in the journey, Mr.Frog decides to make a plan that can help him arrive each city exactly once and pass through each road exactly once. Now give you the information of the cities and roads. Please tell Mr.Frog whether there exists a way that can satisfy his plan.

输入描述:

The first line contains an integer T, where T is the number of test cases. T test cases follow.
For each test case, the first line contains two integers N and M, where N is the number of cities, and M is the number of roads.

Then next M lines follow, the ith line contains two integers Ui and Vi, indicating there is a directed road from city Ui to city Vi.

• 1 ≤ T ≤ 105.
• 1 ≤ N ≤ 105.
• 0 ≤ M ≤ 105.
• 1 ≤ Ui,Vi ≤ N.
• the sum of N in all test cases doesn’t exceed 106.• the sum of M in all test cases doesn’t exceed 106.

输出描述:

For each test case, print a line containing “Case #x:”, where x is the test case number (starting from 1).
In the next line, print the city number in the order of his journey, if there is a way that can satisfy his plan; otherwise print “NO”.

示例1

输入

复制

2
4 3
1 2
2 3
3 4
4 2
1 2
3 4

输出

复制

Case #1:
1 2 3 4
Case #2:
NO

备注:

For the first case, Mr.Frog chooses city 1 to start his trip and travels in the order of 1, 2, 3, 4.
For the second case, there is no way that can satisfy his plan, so print “NO”.
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
const int mod=998244353 ;  
const int N=1e5+10;
int nx[N],f[N];
int T,n,m,fg,u,v,ct=1;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d %d",&n,&m);
        for(int i=1 ; i<=n ; i++)
            nx[i]=f[i]=0;
        fg=0;
        for(int i=1 ; i<=m ; i++){
            scanf("%d %d",&u,&v);
            if(!nx[u]&&!f[v]){
                nx[u]=v;
                f[v]=u;
            }
            else
                fg=1;
        }
        printf("Case #%d:\n",ct++);
        if(fg==1||n!=m+1){
            printf("NO\n");
            continue;
        }
        int S;
        for(int i=1 ; i<=n ; i++){
            if(!f[i]){
                S=i;
                break;
            }
        }
        int tt=0;
        for(int i=S; i; i=nx[i])
            tt++;
        if(tt!=n)
            printf("NO\n");
        else{
            printf("%d",S);
            for(int i=nx[S]; i; i=nx[i])
                printf(" %d",i);
            printf("\n");
        }
    }
    return 0;
}

链接:https://ac.nowcoder.com/acm/problem/15330
来源:牛客网

题目描述

There is a formula:

牛客每日练习----Journey,Bazinga,平分游戏_第1张图片

gcd(a, b) is the greatest common divisor of a and b.

Give you three integers L, R and K. Please calculate the value of the following formula:

牛客每日练习----Journey,Bazinga,平分游戏_第2张图片

输入描述:

The first line contains an integer T, where T is the number of test cases. T test cases follow. 

For each test case, the only line contains three integers L, R and K.

• 1 ≤ T ≤ 20.

• 1≤ L ≤ R ≤1018. 

• 1 ≤ K ≤ 105.

输出描述:

For each test case, output one line containing “Case #x: y”, where x is the test case number (starting
from 1) and y is the answer.

示例1

输入

复制

2
1 5 6
10 20 8

输出

复制

Case #1: 5
Case #2: 3

备注:

For the first case, answer = (1×5) mod 6 = 5.
For the second case, answer = (11×13×15×17×19) mod 8 = 3.
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
const int mod=998244353 ;  
const int N=1e6+10;
ll L,R,k;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll ksm(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%k;
        a=(a*a)%k;
        b>>=1;
    }
    return ans;
}
int main()
{
    ll T,i=0;
    scanf("%lld",&T);
    while(T--)
    {
        i++;
        scanf("%lld%lld%lld",&L,&R,&k);
        ll ct=(R-L+1)/k, jg=1;
        for(ll i=1;i<=k;i++){
            if(gcd(i,k)==1) 	
				jg=(jg*i)%k;
        }
        jg=ksm(jg, ct);
        for(ll i=L+ct*k;i<=R;i++){
            if(gcd(i%k,k)==1) 
				jg=(jg*(i%k))%k;
        }
        printf("Case #%lld: %lld\n",i,jg);
    }
    return 0;
}

链接:https://ac.nowcoder.com/acm/problem/15328
来源:牛客网

题目描述

转眼间又过了一年,又有一届的师兄师姐要毕业了。

有些师兄师姐就去了景驰科技实习。

在景驰,员工是他们最宝贵的财富。只有把每一个人的专业性和独特性结合在一起,他们才会获得成功。他们致力于为所有员工打造一个能够被激励,并分享公司成功的工作环境。 
创新精神:为了改变人类出行而不断迎接全新挑战。
团队协作:依靠集体的智慧,坦诚无私地帮助彼此。
结果导向:在所有方面都力争做到中国第一和世界一流,并对结果负责。 
共同成长:学习永无止境,通过个人发展和职业成长实现成就。

GUDTACM集训队教练孙壕又来请大家大搓一顿。

茶余饭足以后,有人提议不如来玩游戏吧。狼人杀谁是卧底跳一跳都已经玩得太多了,所以大家决定玩一个更加有挑战性的游戏。

集训队一共有n位同学,他们都按照编号顺序坐在一个圆桌旁。第i位同学一开始有a[i]个硬币,他们希望使得每位同学手上的硬币变成相同的数目。每一秒钟,有且仅有一位同学可以把自己手上的一枚硬币交给另一位同学,其中这两位同学中间必须间隔k位同学。

现在问的是最少几秒后所有同学手上的有相同数量的硬币

输入描述:

第一行输入两个整数n,k(1<=n<=1000000,0<=k<=n)
接下来的一行有n个整数,第i个整数a[i](0<=a[i]<=1e9)表示第i位同学手上的硬币的数量。

输出描述:

一个整数,表示最少几秒后所有同学手上的有相同数量的硬币。如果不可能,则输出gg。

示例1

输入

复制

5 0
2 3 1 5 4

输出

复制

3
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
const int mod=998244353 ;  
const int N=1e6+10;
int n,m;
ll a[N];
ll d[N],sum,jg;
int main()
{
    cin>>n>>m;
    for(int i=0;i>a[i];
    if(sum%n)
        jg=-1;
	else if(m>=n-1){
        for(int i=1;i

 

你可能感兴趣的:(牛客网)