Codeforces-Applejack and Storages

42 篇文章 1 订阅
7 篇文章 0 订阅

世 上 没 有 绝 望 的 处 境
只 有 对 处 境 绝 望 的 人

题目描述

This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).
Applejack will build the storages using planks, she is going to spend exactly one plank on each side of the storage. She can get planks from her friend’s company. Initially, the company storehouse has n planks, Applejack knows their lengths. The company keeps working so it receives orders and orders the planks itself. Applejack’s friend can provide her with information about each operation. For convenience, he will give her information according to the following format:

  • + x: the storehouse received a plank with length x
  • − x: one plank with length x was removed from the storehouse (it is guaranteed that the storehouse had some planks with length x).

Applejack is still unsure about when she is going to order the planks so she wants to know if she can order the planks to build rectangular and square storages out of them after every event at the storehouse. Applejack is busy collecting apples and she has completely no time to do the calculations so she asked you for help!

We remind you that all four sides of a square are equal, and a rectangle has two pairs of equal sides.

输入

The first line contains a single integer n (1≤n≤105): the initial amount of planks at the company’s storehouse, the second line contains n integers a1,a2,…,an (1≤ai≤105): the lengths of the planks.

The third line contains a single integer q (1≤q≤105): the number of events in the company. Each of the next q lines contains a description of the events in a given format: the type of the event (a symbol + or −) is given first, then goes the integer x (1≤x≤105).

输出

After every event in the company, print “YES” if two storages of the required shape can be built from the planks of that company’s set, and print “NO” otherwise. You can print each letter in any case (upper or lower).

Hint

After the second event Applejack can build a rectangular storage using planks with lengths 1, 2, 1, 2 and a square storage using planks with lengths 1, 1, 1, 1.

After the sixth event Applejack can build a rectangular storage using planks with lengths 2, 2, 2, 2 and a square storage using planks with lengths 1, 1, 1, 1.

题目大意

有一个商家,想用n块木板围城两个仓库(四个木板围成一个)这两个仓库至少有一个是正方形的仓库,其余随意。每一次都会收入或者卖出木板,他现在想知道,可不可一搭建自己想要的两个仓库(一个正方形,一个长方形 or 正方形)。
注意n是可以增加和减少的,最初始输入的只是最初状态的木板的个数。

思路分析

统计所有对边的个数,同时也要统计所有可以构成正方形的个数,当对边个数小于4的时候(两个对边一个矩形),是不可以的。当对边数大于4的时候,只有无法构成正方形的不可以。所以,统计好之后一波if else 就过了。

AC时间到

#include<algorithm>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<stdio.h>
#include<vector>
#include<string>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#pragma warning(disable:4244)
#define PI 3.141592653589793
#pragma GCC optimize(2)
#define accelerate cin.tie(NULL);cout.tie(NULL);ios::sync_with_stdio(false);
#define EPS 1.0e-8
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const char char_inf = 127;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll read() {
	ll c = getchar(), Nig = 1, x = 0;
	while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-')Nig = -1, c = getchar();
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
inline void out(ll a) {
	if (a < 0)putchar('-'), a = -a;
	if (a >= 10)out(a / 10);
	putchar(a % 10 + '0');
}
ll phi(ll n)
{
	ll ans = n, mark = n;
	for (ll i = 2; i * i <= mark; i++)
		if (n % i == 0) { ans = ans * (i - 1) / i; while (n % i == 0)n /= i; }
	if (n > 1)ans = ans * (n - 1) / n; return ans;
}
ll qpow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1)res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}
ll mat_mod;
struct Mat {
	ll m[10][10];
};
Mat Mul(Mat A, Mat B, ll mat_size) {
	Mat res;
	memset(res.m, 0, sizeof(res.m));
	for (int i = 0; i < mat_size; i++)for (int j = 0; j < mat_size; j++)for (int k = 0; k < mat_size; k++)
		res.m[i][j] = (res.m[i][j] + (A.m[i][k] * B.m[k][j]) % mat_mod) % mat_mod;
	return res;
}
Mat mat_qpow(Mat data, ll power, ll mat_size) {
	Mat res;
	memset(res.m, 0, sizeof(res.m));
	for (int i = 0; i < mat_size; i++)res.m[i][i] = 1;
	while (power) {
		if (power & 1)res = Mul(res, data, mat_size);
		data = Mul(data, data, mat_size), power >>= 1;
	}
	return res;
}
#define Floyd for(int k = 1; k <= n; k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
#define read read()
int save[100005];
int tot;//边的个数
int can;//过4个的
void judge(bool sta, int num)
{
	if (sta)//加的情况
	{
		save[num]++;
		if (save[num] == 4)can++;
		if (save[num] % 2 == 0)tot++;
	}
	else//减的情况
	{
		save[num]--;
		if (save[num] == 3)can--;
		if (save[num] & 1)tot--;
	}
}
int main()
{
	accelerate;
	int n, num;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> num;
		judge(1, num);
	}
	char mark[5];//用字符串避免缓冲区字符读取的问题
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> mark >> num;
		switch (mark[0])
		{
		case '+': judge(1, num); break;
		case '-': judge(0, num); break;
		}
		if (tot >= 4)
		{
			if (can == 0)cout << "NO" << endl;
			else cout << "YES" << endl;
		}
		else cout << "NO" << endl;
	}
}

By-轮月

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Round moon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值