牛客小白月赛90

牛客小白月赛90_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ (nowcoder.com)

A-小A的文化节_牛客小白月赛90 (nowcoder.com) 

题目说什么,做什么即可 

// Problem: 小A的文化节
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78306/A
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;
int a[maxn];
void solve()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i += 1)cin >> a[i];
	int ans = 0;
	while(m--)
	{
		int k;cin >> k;
		ans += a[k];
	}
	cout << ans;
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
   // cin >> T;
    while (T--) solve();
    return 0;
}

 

B-小A的游戏_牛客小白月赛90 (nowcoder.com) 

 

因为输了没分,平局没有分差,多赢的人一定比对方多x(3的倍数)分

// Problem: 小A的游戏
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78306/B
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;

void solve()
{
	cin >> n >> m;
	if(n - m == 0 || (n - m) % 3 == 0)
	cout << "Yes" << endl;
	else
	cout << "No" << endl;
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

 

C-小A的数字_牛客小白月赛90 (nowcoder.com)

 

特殊点s = 1时

此时ans最终 = 0;

只能 + 1得最小值

// Problem: 小A的数字
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78306/C
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;

void solve()
{
    string s; 
    cin >> s;
    int ans = 0;
    for(auto &i : s)
    ans = ans * 10 + (i == '0' ? 1 : 0);
    if(ans == 0) cout << (s.back() == '1' ? 2 : 1) << endl;
    else cout << ans << endl;
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

 

D-小A的线段(easy version)_牛客小白月赛90 (nowcoder.com)

对于每一条线段 == >> 只有选 or 不选2种情况

因为线段数m <= 10dfs即可 

 

因为这是easy版m <= 10所以不需要MOD操作,达不到

 

// Problem: 小A的线段(easy version)
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78306/D
// Memory Limit: 524288 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B, ans;
int Lg[11][2];
int a[maxn];
void dfs(int x)
{
	//cout << ++d << endl;
	if(x == m + 1)
	{
		for(int i = 1;i <= n;i++)
		if(a[i] < 2)return;
		ans += 1;
		return;
	}	
	for(int i = Lg[x][0]; i <= Lg[x][1]; i++)
	a[i] += 1;
	dfs(x + 1);//选择
	for(int i = Lg[x][0]; i <= Lg[x][1]; i++)
	a[i] -= 1;
	dfs(x + 1);//不选择
}

void solve()
{
	cin >> n >> m;
	for(int i = 1;i <= m;i++)cin >> Lg[i][0] >> Lg[i][1];
	dfs(1);
	cout << ans << endl;
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
   // cin >> T;
    while (T--) solve();
    return 0;
}

E-小A的任务_牛客小白月赛90 (nowcoder.com)

 

提供一个手造数据

输入:

5 2

1 1 1 1 1

3 5 3 2 1

1

5

输出:

4

19

根据题意表达,自己根据该数据推,不难发现,当k不同时,我们对于B任务的选择顺序是不同的

== 某些情况下前者 无法推导出 后者(例:k == 2的顺序 和 k == 4选择顺序是不同的,对于上诉手造数据k == 1的顺序对于k == 5时是不可取的)

因此最初如果想直接使用优先队列对全体预处理是错误的 

所以:对于每一次的k我们都用优先队列进行一次筛选

1:当优先队列大小 == k时说明目前可达成的B任务已经满足需求,我们进行一次更新答案

2:当优先队列大小 > k时说明 可达成的B任务已经满足需求 并且有多种情况可以选择,淘汰耗时最长的情况

因为每一次完成Bi的前提是完成a(1-i)

我们每一次淘汰最长Bi时,减去该Bi值即可

因此每一次筛选时我们的min是ans本身和 suma + sumb对比

1:suma == 做bi前ai的前缀和

2:sumb == 已做的b任务之和

// Problem: 小A的任务
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78306/E
// Memory Limit: 524288 MB
// Time Limit: 6000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;
int a[maxn],b[maxn];
void solve()
{
	cin >> n >> d;
	for(int i = 1;i <= n;i++)cin >> a[i];
	for(int i = 1;i <= n;i++)cin >> b[i];
	while(d--)
	{
		cin >> k;
		priority_queue<int>Q;
		int ans = 1e18, suma = 0, sumb = 0;
		for(int i = 1;i <= n;i++)
		{
			suma += a[i];
			sumb += b[i];
			Q.emplace(b[i]);
			if(Q.size() > k)
			{
				sumb -= Q.top();
				Q.pop();
			}
			if(Q.size() == k)
			ans = min(ans, suma + sumb);
		}
		cout << ans << endl;
	}
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
   // cin >> T;
    while (T--) solve();
    return 0;
}

/*
1 2 3 4
4 1 2 3
1
2
3


4
5
8
15
*/

F-小A的线段(hard version)_牛客小白月赛90 (nowcoder.com) 

 

不会 

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值