牛客2019跨年AK场

【牛】华华教月月做数学
链接:https://ac.nowcoder.com/acm/contest/3800/A
来源:牛客网

题目描述
找到了心仪的小姐姐月月后,华华很高兴的和她聊着天。然而月月的作业很多,不能继续陪华华聊天了。华华为了尽快和月月继续聊天,就提出帮她做一部分作业。
月月的其中一项作业是:给定正整数A、B、P,求A^B\mod PA
B
modP的值。华华觉得这实在是毫无意义,所以决定写一个程序来做。但是华华并不会写程序,所以这个任务就交给你了。
因为月月的作业很多,所以有T组询问。
输入描述:
第一行一个正整数T表示测试数据组数。
接下来T行,每行三个正整数A、B、P,含义如上文。
输出描述:
输出T行,每行一个非负整数表示答案。
示例1
输入
复制
2
2 5 10
57284938291657 827493857294857 384729583748273
输出
复制
2
18924650048745
备注:
1\le T\le10^31≤T≤10
3
,1\le A,B,P\le10^{18}1≤A,B,P≤10
18

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int unsigned long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define x first
//#define y second

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0}; 

typedef __int128 INT;
typedef pair<double, int> PDI;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 2010 + 10;
const int M = 3e6 + 10;
const int mod = 2333;
const int PP = 13331;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

int qmi(int a, int b, int p){
	INT x = a %= p;
	INT res = 1;
	while(b){
		if (b & 1)   res = res * x % p;
		x = x * x % p;
		b >>= 1;
	}
	return (int)res % p;
}

signed main(){
	int T;
	cin >> T;
	while(T --){
		int a, b, p;
		cin >> a >> b >> p;
		cout << qmi(a, b, p) % p << endl;
	}
	return 0;
}

【网】签到题I
链接:https://ac.nowcoder.com/acm/contest/3800/C
来源:牛客网

题目描述
众所周知,给定一个可重集,求它的第 k 小的数字是一个很难的问题,那么现在就来考考你
输入描述:
第一行两个整数 n,k,表示这个可重集的大小以及询问的 k

第二行一共 n 个非负整数,表示这个可重集中所有的数字
输出描述:
一行一个整数,表示这个可重集的第 k 小的数字是什么
示例1
输入
复制
3 1
3 1 2
输出
复制
1
备注:
数据范围
1 \le k \le n \le 10^51≤k≤n≤10
5

所有的数字不超过 10^510
5

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define x first
//#define y second

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0}; 

//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1e5 + 10;
const int M = 3e6 + 10;
const int mod = 2333;
const int PP = 13331;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

int a[N];

signed main(){
	int n, k;
	scanf("%lld%lld", &n, &k);
	
	for (int i = 1; i <= n; i ++){
		scanf("%lld", &a[i]);
	}
	
	sort(a + 1, a + 1 + n);
	
	cout << a[k] << endl;
	
	return 0;
}

【祝】Rinne Loves Study
链接:https://ac.nowcoder.com/acm/contest/3800/D
来源:牛客网

目描述
Rinne 喜欢使用一种奇怪的方法背单词,现在这些单词被放在了一个 n \times mn×m 的格子里。由于背单词是一个令人烦躁的事情,所以她决定每天只背同一行或者同一列的单词。她一共会背 T 次单词,为了方便巩固,她现在想知道:对于每个单词,最后一次背是什么时候呢?
她这么可爱当然会算啦!但是她想考考你。
输入描述:
第一行三个整数 n,m,T。
接下来 T 行,第 i+1 行描述第 i 天干了什么,每行的格式如下:
1 x:说明她在这一天背了第 x 行的单词;
2 y说明她在这一天背了第 y 列的单词。
输入的所有量的具体意义请参考「题目描述」。
输出描述:
输出一个 n \times mn×m 的矩阵 a,a_{i,j}a
i,j

表示第 i 行第 j 列这个单词最后一次被背诵是在第几天。
示例1
输入
复制
3 3 3
1 2
2 3
1 3
输出
复制
0 0 2
1 1 2
3 3 3
备注:
n \times m \leq 10^5,T \leq 10^5n×m≤10
5
,T≤10
5
标记每一行列即可

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

//#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define x first
//#define y second

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0}; 

//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1e5 + 10;
const int M = 3e6 + 10;
const int mod = 1000000007;
const int PP = 13331;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

int row[N], col[N];

signed main(){
	int n, m, q;
	scanf("%lld%lld%lld", &n, &m, &q);
	
	for (int i = 1; i <= q; i ++){
		int x, y;
		scanf("%lld%lld", &x, &y);
		if (x == 1){
			row[y] = i;
		}
		else if (x == 2){
			col[y] = i;
		}
	}
	
	for (int i = 1; i <= n; i ++){
		for (int j = 1; j <= m; j ++){
			cout << max(row[i], col[j]) << " ";
		}
		cout << endl;
	}
	
	return 0;
}

【大】约数
链接:https://ac.nowcoder.com/acm/contest/3800/E
来源:牛客网

Actci上课睡了一觉,下课屁颠屁颠的去找数学老师补课,问了老师一个题目:
给出两个数a,b,问a和b的全部公约数是什么?
数学老师一看这道题太简单了,不屑回答,于是就交给了你。
输入描述:
一行两个数a,b.
输出描述:
a和b的全部公约数,每个数字之间空格隔开。
示例1
输入
复制
25 37
输出
复制
1
示例2
输入
复制
25 100
输出
复制
1 5 25
备注:
对于100%的数据,1 ≤ a,b ≤ 1013
找到所有的公约数看是否相同

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define x first
//#define y second

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0}; 

//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 2010 + 10;
const int M = 3e6 + 10;
const int mod = 2333;
const int PP = 13331;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

vector<int> get_divisors(int x){
	vector<int> res;
	for (int i = 1; i <= x / i; i ++){
		if (x % i == 0){
			res.push_back(i);
			if (i != x / i)   res.push_back(x / i);
		}
	}
	sort(res.begin(), res.end());
	return res;
}

signed main(){
	int a, b;
	cin >> a >> b;
	
	auto res1 = get_divisors(a);
	auto res2 = get_divisors(b);
	
	for (auto x : res1){
		if (find(res2.begin(), res2.end() , x) != res2.end()){
			cout << x << " ";
		}
	}
	
	cout << endl;
	
	return 0;
}

或者是最大公约数的因子的乘积的任意组合

#include<iostream>
#include<set>
#define int long long

using namespace std;
typedef pair<int,int> PII;
const int N=1e6+10;

int c[100];
int cnt,e[N],cot;
int tmp=1;
set<int> mset;

int gcd(int a,int b)
{
    return b ? gcd(b,a%b) : a;
}

void dfs(int u)
{
    if(u>cnt)
    {
        mset.insert(tmp);
        return;
    }
    for(int j=0;j<=1;j++)
    {
        if(j) tmp*=c[u];
        dfs(u+1);
        if(j) tmp/=c[u];
    }
}

signed main()
{
    int a,b;
    cin>>a>>b;
    int d=gcd(a,b);
    for(int i=2;i*i<=d;i++)
    {
        if(d%i==0)
        {
            while(d%i==0)
            {
                c[++cnt]=i;
                d/=i;
            }
        }
    }
    if(d!=1) c[++cnt]=d;
    dfs(1);
    for(int x:mset) printf("%lld ",x);
}

【家】神秘钥匙
链接:https://ac.nowcoder.com/acm/contest/3800/F
来源:牛客网

题目描述
clccle一行𝑛个人来到了一个诡异的世界,她们需要去寻找逃出这个地方的方法——找到神秘的所罗门之匙
她们决定从中随机选出一些人去寻找钥匙,并在其中选出一个队长,clccle不想知道自己有多大几率被选中,她只想知道一共有多少种选择的方案 (选出的人数要在1−𝑛之间,不同的队长算不同的方案)。
方案数对1000000007取模
输入描述:
第一行,一个整数𝑛。
输出描述:
一个整数,表示方案数。
示例1
输入
复制
2
输出
复制
4
说明
四种方案:(1),(2),(1,2)其中1是队长,(2,1),其中2是队长
备注:
1 ≤ 𝑛 ≤ 109

找规律,或者除了队长每个人都有两种选择,队张有n种选择

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define x first
//#define y second

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0}; 

//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1e5 + 10;
const int M = 3e6 + 10;
const int mod = 1000000007;
const int PP = 13331;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

int qmi(int a, int b, int mod){
	int res = 1;
	while(b){
		if (b & 1)   res = res % mod * a % mod;
		a = a % mod * a % mod;
		b >>= 1;
	}
	return res % mod;
}

signed main(){
	int n;
		
	scanf("%lld", &n);
	
	cout << n * qmi(2, n - 1, mod) % mod << endl;
		
	return 0;
}

、、

【跨】小sun的假期

链接:https://ac.nowcoder.com/acm/contest/3800/G
来源:牛客网

题目描述
小 sun 非常喜欢放假,尤其是那种连在一起的长假,在放假的时候小 sun 会感到快乐,快乐值等于连着放假的天数,现在小 sun 把他的安排表告诉你,希望你告诉他在他的安排表中, 他的最大快乐值。

当某天没有安排的时候就是放假。
输入描述:
第一行两个数n,m,代表总共有n天,m个安排。

接下来有m行,每行是一个安排l,r,代表从第l天到第r天,小sun有安排了。

安排可能会重复。
输出描述:
输出一行,在这个安排表中,小sun最大的快乐值。
示例1
输入
复制
5 1
2 3
输出
复制
2
备注:
数据范围:
n\leq 1e9, m\leq 1e5n≤1e9,m≤1e5
1 \leq l,r\leq n1≤l,r≤n

类似于区间和并

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define x first
//#define y second

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0}; 

//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1e5 + 10;
const int M = 3e6 + 10;
const int mod = 2333;
const int PP = 13331;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

struct Node{
	int l ,r;
	bool operator<(const Node &W)const{
		return l < W.l;
	}
}node[N];

signed main(){
	int n, m;
	scanf("%lld%lld", &n, &m);
	
	for (int i = 1; i <= m; i ++){
		scanf("%lld%lld", &node[i].l, &node[i].r);
	}
	
	sort(node + 1, node + 1 + m);
	
	int ans = max(0ll, node[1].l - 1);
	int last = 0;
	int st = node[1].l, ed = node[1].r;
	
	for (int i = 2; i <= m; i ++){
		if (node[i].l <= ed + 1){
			ed = max(ed, node[i].r);
		}
		else{
			ans = max(ans, node[i].l - ed - 1);
			st = node[i].l;
			ed = node[i].r;
		}
	}
	
	ans = max(ans, n - ed);
	
	cout << ans << endl;
	
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值