NEUQ-2021自主学习训练-1

A - Prison Break

#include <iostream>
using namespace std;
int main ()
{
	int t;
	cin >> t;
	while (t --)
	{
		int a, b;
		cin >> a >> b;
		cout << a * b << endl;		
	}
	return 0;
}

B - Restore Modulo

#include <iostream>
#include <set>
using namespace std;

set <int> s;
const int N = 1e5 + 5;
int a[N];

void solve ()
{
	s.clear();
	
	int n;
	cin >> n;
	
	int top = 0;
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i];
		top = max (a[i], top);
	}	
	
	if (n == 1 || n == 2)
	{
		cout << 0 << endl;
		return;
	}		

	for (int i = 0; i < n - 1; i ++)
	{
		s.insert(a[i + 1] - a[i]);
	}
	
	if (s.size() == 1) cout << 0;
	else if (s.size() == 2)
	{
		int m = *s.rbegin() - *s.begin();
		int c = *s.rbegin();
		if (m && c && m > top) cout << m << ' ' << c;
		else cout << -1;
	}
	else cout << - 1;
	
	cout << endl;
}

int main ()
{
	int t;
	cin >> t;
	while (t --)
	{			
		solve();
	}
	return 0;
}

C - Basic Diplomacy

#include <iostream>
#include <map>
#include <vector>
#include <cstring>
using namespace std;

const int N = 2e5 + 5;
const int inf = 0x3f3f3f;

vector <int> v[N];
int ans[N];
map <int, int> cnt;

void solve ()
{
	memset (v, 0, sizeof v);
	memset (ans, 0, sizeof ans);
	cnt.clear();
	
	int n, m;
	cin >> n >> m;
	
    for (int i = 0 ; i < m ; i ++)
	{
		int k;
		cin >> k;
		for(int j = 0 ; j < k ; j ++)
		{
			int x;
			cin >> x;
			v[i].push_back(x);
		}
	}
	
	int mid = m - m / 2;
	
    for (int i = 0 ; i < m ; i ++)
	{
		if (v[i].size() == 1)
		{
			int x = v[i][0];
			ans[i] = x;
			cnt[x] ++;
			if (cnt[x] > mid)
			{
				puts ("NO");
				return;
			}
		}
	}
	
	puts ("YES");
	
	for (int i = 0; i < m; i ++)
	{
		if (v[i].size() == 1) continue;
		int counts = inf, place = inf;
		for (int j = 0 ; j < v[i].size(); j ++)
		{
			int x = v[i][j];
			if (cnt[x] < counts)
			{
				counts = cnt[x];
				place = j;
			}
		}
		ans[i] = v[i][place];
		cnt[ans[i]] ++;
	}
	
	for (int i = 0; i < m ; i ++) 
	{
		cout << ans[i] << " ";
	}
	
	cout << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t --)
    {
		solve ();
    }
    return 0;
}

D - Playlist

#include <iostream>
#include <vector>
using namespace std;

const int N = 1e5 + 5;
int a[N], ne[N];
bool st[N];

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

int main()
{
	int t;  
	cin >> t;
	while (t --)
	{
		int n;
		cin >> n; 
		
		vector <int> del;
		for (int i = 0; i < n; i ++)
		{
			cin >> a[i];
			st[i] = 0;
			ne[i] = (i + 1) % n;
			del.push_back (i);
		}
		
		vector <int> ans;
		while (del.size())
		{
			vector <int> newdel;
			for (auto it : del)
			{
				if (st[it]) continue;
				if (gcd (a[it], a[ne[it]]) == 1)
				{
					ans.push_back (ne[it] + 1);
					st[ne[it]] = 1;
					ne[it] = ne[ne[it]];
					newdel.push_back (it);
				}
			}
			del = newdel;
		}
		
		cout << ans.size();
		for (int it : ans) cout << " " << it;
		cout << endl;
	}
	return 0;
}

E - Class

#include <iostream>
using namespace std;
int main ()
{
	int x, y;
	cin >> x >> y;
	
	cout << (x + y) * (x - y) / 4 << endl;
	return 0;
}

F - String

#include <iostream>
#include <cstring>
#define int long long
using namespace std;

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

signed main ()
{
	int n;
	while (cin >> n)
	{
		string s;
		cin >> s;
		int na = 0, nv = 0, ni = 0, nn = 0;
		for (auto it : s)
		{
			if (it == 'a') na ++;
			else if (it == 'v') nv ++;
			else if (it == 'i') ni ++;
			else if (it == 'n') nn ++;
		}
		int x = na * nv * ni * nn;
		int y = n * n * n * n;
		int g = gcd (x, y);
		x /= g;
		y /= g;
		if (!x) cout << "0/1\n";
		else cout << x << '/' << y << endl;
	}
	return 0;
}

G - Traffic

#include <iostream>
#include <cstring>
using namespace std;

const int N = 10000 + 5;
int a[N], b[N];
int n, m;

bool test (int t)
{
	for (int i = 0; i < m; i ++)
	{
		if (a[b[i] + t]) return false;
	}
	return true;
}

int main ()
{
	while (cin >> n >> m)
	{
		memset (a, 0, sizeof a);
		memset (b, 0, sizeof b);
		for (int i = 0; i < n; i ++)
		{
			int x;
			cin >> x;
			a[x] ++;
		}
		for (int i = 0; i < m; i ++)
		{
			cin >> b[i];
		}
		for (int t = 0;;t ++)
		{
			if (test(t))
			{
				cout << t << endl;
				break;				
			}
		}
	}
	return 0;
}

H - Budget

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main ()
{
	int n;
	while (cin >> n)
	{
		double sum = 0;
		while (n --)
		{
			string s;
			cin >> s;
			
			int x = *s.rbegin() - '0';
			
			if (x >= 5) sum += 10 - x;
			else sum -= x;
		}
		cout << fixed << setprecision (3) << sum / 1000 << endl;
	}
	return 0;
}

I - Worker

#include <iostream>
#define int long long
using namespace std;

const int N = 1000 + 5;
int a[N];

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

int lcm (int x, int y)
{
	return x / gcd (x, y) * y;
}

void solve (int n, int m)
{
	int x = 1;
	
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i];
		x = lcm (a[i], x);
	}
	
	int sum = 0;
	
	for (int i = 0; i < n; i ++)
	{
		sum += x / a[i];
	}
	
	if (m % sum)
	{
		puts ("No");
		return;
	}
	
	puts ("Yes");
	
	int y = m / sum;
	
	for (int i = 0; i < n - 1; i ++)
	{
		cout << y * (x / a[i]) << ' ';
	}
	
	cout << y * (x / a[n - 1]) << endl;
}

signed main ()
{
	int n, m;
	while (cin >> n >> m)
	{
		solve (n, m);		
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值