AtCoder Beginner Contest 180

A.

// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <random>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
LL h[maxn],w[maxn];
LL s1[maxn];// 奇数的前缀差分和
LL s2[maxn];// 偶数的前缀差分和
int n, m;
int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
//	 freopen("out.txt", "w", stdout);
#endif
	int n, a, b;
	cin >> n >> a >> b;
	cout << n - a + b;
	return 0;
}

B.模拟

// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <random>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
double a[maxn];
int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
//	 freopen("out.txt", "w", stdout);
#endif
	int n;
	LL x;
	cin >> n;
	LL ans1 = 0;
	double ans2 = 0;
	LL ans3 = -INF;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		ans1 += abs(x);
		ans2 += x * x;
		ans3 = max(ans3, abs(x));
	}
	cout << ans1 << endl;
	printf("%.12lf\n", sqrt(ans2));
	cout << ans3 << endl;
	return 0;
}

C.根号n枚举,放到vector排个序

// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <random>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
double a[maxn];
vector<LL> v;
int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
//	 freopen("out.txt", "w", stdout);
#endif
	IO;
	LL n;
	cin >> n;
	LL m = sqrt(double(n));
	for (LL i = 1; i <= m; i++)
	{
		if (n % i == 0)
		{
			LL t = n / i;
			if (t == i)
				v.push_back(i);
			else
			{
				v.push_back(i);
				v.push_back(t);
			}
		}
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		cout << v[i] << endl;
	}
	return 0;
}

D.判断当前哪种方式增长的更慢,选择更慢的一种。

// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <random>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
// int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

LL x, y, a, b;

int main()
{
#ifdef WXY
    freopen("in.txt", "r", stdin);
//	 freopen("out.txt", "w", stdout);
#endif
    IO;
    cin >> x >> y >> a >> b;
    int cnt = 0;

    while (x < (b + x) / a && x < y / a)
    {
        x = x * a;
        cnt++;
    }
    // cout << x << endl;
    LL t = y - x - 1;
    cout << t / b + cnt;
    return 0;
}

E.

问的学妹,是个状态压缩DP,tql。

i为当前状态,找到当前状态的最后一个1的位置,将它看做当前到达的最后一个点,通过它继续往没到达的地方转移。

注释齐全

// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <random>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
// int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct Node
{
	LL a, b, c;
} a[maxn];
LL dis[20][20];
LL bit[20];// 记录 1 的位置
LL dp[1 << 20][20];
LL cal(int i, int j)
{
	return abs(a[i].a - a[j].a) + abs(a[i].b - a[j].b) + max(0LL, a[j].c - a[i].c);
}
int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
//	 freopen("out.txt", "w", stdout);
#endif
	IO;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i].a >> a[i].b >> a[i].c;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			dis[i][j] = cal(i, j);
	// 预处理 两点间的距离
	bit[0] = 1;
	for (int i = 1; i <= n; ++i)
		bit[i] = bit[i - 1] << 1;

	int all = bit[n] - 1; // 所有种情况 all 为全一的情况 也就是经过了所有点的情况
	for (int i = 1; i <= all; ++i)
		for (int j = 1; j <= n; ++j)
			dp[i][j] = 1e9;// 初始化

	dp[1][1] = 0;// 当这条路上只有一个点且这个点为1的时候,显然为还没有发生转移,花费为 0
	for (int i = 1; i < all; ++i) // 所有状态 用 01 串来枚举
	{
		for (int j = 1; j <= n; ++j)
		{
			if (i & bit[j - 1])// 假如点 j 在当前经过的点中,且为最后一个点
			{
				// 用 bit[j-1] 找到对应位置的 1
				// 利用 点 j 进行转移
				for (int k = 1; k <= n; ++k)
				{
					if (!(i & bit[k - 1]))// 当前点还没有在路径中
						dp[i | bit[k - 1]][k] = min(dp[i][j] + dis[j][k], dp[i | bit[k - 1]][k]);
					// 更新当前最终点为 k 的时候的最优解
				}
			}
		}
	}
	LL ans = INF;
	for (int i = 2; i <= n; ++i)
		ans = min(ans, dp[all][i] + dis[i][1]); //枚举一个点 使 1号点经过所有点后到这个点加上从这个点回到 1 号点最小
	cout << ans;
	return 0;
}

F.

待定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值