牛客小白月赛 17

牛客小白月赛 17

  • C 异或和 (签到题)
  • I-坐电梯 (思维)
  • B-扫雷 (模拟)
  • D-解密 (模拟)
  • A-小sun的假期
  • F-小黄鸭 (积分+浮点二分)
  • E.图的遍历(判奇环)
  • G.区间求和(莫队)
  • H.取球游戏(概率dp)
  • J.计数(组合数学)

C 异或和 (签到题)

#include
#include
#include
#include
#include
#include
#include

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//

signed main()
{
	int n = read();
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int x = read();
		ans ^= x;
	} 
	printf("%lld\n", ans);
	return 0;	
} 

I-坐电梯 (思维)

#include
#include
#include
#include
#include
#include
#include

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define inf 1e9 + 100
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 100010;

signed main()
{
	int n = read(), k = read();
	int maxx = 0;
	for (int i = 0; i < n; ++i) {
		int x = read();
		maxx = max(maxx, x);
	}
	printf("%lld\n", maxx - 1 + maxx - k);

	return 0;
} 

B-扫雷 (模拟)

#include
#include
#include
#include
#include
#include
#include

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MOD 1e9 + 7
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 1010;
int n, m;
char mp[N][N];
 
int edge(int i, int j) {
	if(i < 0 || i >= n || j < 0 || j >= m) return 0;
	return 1;
}

signed main()
{
	n = read(), m = read();
	for(int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> mp[i][j];
		}
	} 
	for(int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int cnt = 0;
			if (mp[i][j] == '*') printf("*");
			else if (mp[i][j] == '.') {
				if(edge(i - 1, j - 1) && mp[i - 1][j - 1] == '*')	cnt++;
				if(edge(i - 1, j) && mp[i - 1][j] == '*')	cnt++;
				if(edge(i - 1, j + 1) && mp[i - 1][j + 1] == '*')	cnt++;
				
				if(edge(i, j - 1) && mp[i][j - 1] == '*')	cnt++;
				if(edge(i, j + 1) && mp[i][j + 1] == '*')	cnt++;
				
				if(edge(i + 1, j - 1) && mp[i + 1][j - 1] == '*')	cnt++;
				if(edge(i + 1, j) && mp[i + 1][j] == '*')	cnt++;
				if(edge(i + 1, j + 1) && mp[i + 1][j + 1] == '*')	cnt++;
				printf("%lld", cnt);
			}
		}
		printf("\n");
	} 
	return 0; 
}

D-解密 (模拟)

#include
#include
#include
#include
#include
#include
#include

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MOD 1e9 + 7
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 1010;
const int mod = 26;
int arr1[N], arr2[N];
string str;
signed main()
{
	int k1 = read(), k2 = read();
	string s;
	cin >> s;
	
	for (int i = 0; i < s.size(); i++) {
		int flag = 0;
		if (s[i] >= 'A' && s[i] <= 'Z') flag = 1;
		if (flag) s[i] -= 'A';
		else s[i] -= 'a';
//		printf("s[i] == %c\n", s[i]);
		for (int j = 0; j < 26; j++) {
			int k = 0;
			int tmp = (k1 * j + k2) % mod;
//			printf("tmp == %lld\n", tmp);
			if (s[i] == tmp) {
				char c;
				if (flag) c = j + 'A';
				else c = j + 'a';
				printf("%c", c);
				break;
			}
//			printf("%lld\n", ++k);
		}
	}
	return 0; 
}

A-小sun的假期

#include
#include
#include
#include
#include
#include
#include

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define inf 0x3f3f3f3f
#define PI acos(-1)
#define MOD 1e9 + 7
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 100010;
struct node {
	int l, r;
}a[N];

int n, m;

bool cmp(node a, node b) {
	return a.l < b.l;
}

signed main()
{
	n = read(), m = read();
	for (int i = 0; i < m; ++i) a[i].l = read(), a[i].r = read();
	sort(a, a + m, cmp);
	int ans = -inf;
	int R = a[0].r;
	for (int i = 1; i <= m; ++i) {
		if (a[i].l > R && a[i].l - R - 1 > ans) ans = a[i].l - R - 1;
		if (a[i].r > R) R = a[i].r;
	}
	ans = max(ans, n - R);
	printf("%lld\n", ans);	
	return 0;
}

F-小黄鸭 (积分+浮点二分)

#include
#include
#include
#include
#include
#include
#include

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define inf 1e9 + 100
#define pi acos(-1)
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 100010;
int R, m;

bool check(double mid) {
    return pi * (R * mid * mid - mid * mid * mid / 3) >= m;
}
signed main()
{
	R = read(), m = read();
	double l = 0, r = R + R;
	while (r - l > 1e-4) {
		double mid = (l + r) / 2.0;
		if (check(mid)) r = mid;
		else l = mid;
	} 
	printf("%.2lf", R + R - r);
    return 0;
}

待更新… (其实是还没学会)

E.图的遍历(判奇环)

G.区间求和(莫队)

H.取球游戏(概率dp)

J.计数(组合数学)

你可能感兴趣的:(牛客OJ,数学,c++,算法,二分查找,字符串)