HDU 4961 Magical Forest

Doubi Gao3 posted @ 2014年8月12日 21:16 in acm with tags 模拟 , 966 阅读

大意:虚拟出一个2*10^9 * 2*10^9的数组内存空间,现在这个内存空间初始化为0,并且对其中的某些元素进行赋初值。后接着一系列的操作使得这个数组的行和列得以交换,中间还对某一行或者是某一列元素的值进行询问。

前段时间写过一个类似的题,二哥的内存。没想到在多校遇到了这道题,只不过数据范围改一下,但是有一个限制条件,即交换的两行(列)必须都有水果或者都没水果,注意这一点,用map映射一下值就可以了。

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <map>
using namespace std;

map<long long int, int> mp;
map<int, int> r, c;

int n, m, k;

void swap(int &a, int &b)
{
    int t = a;
    a = b;
    b = t;    
}

int main()
{
	int T, kase = 0;
	for(scanf("%d", &T); T > 0; T--)
	{
		scanf("%d%d%d", &n, &m, &k);
		
		mp.clear();
		r.clear();
		c.clear();
		
		for(int i = 0; i < k; i++)
		{
			int x, y, z;
			scanf("%d%d%d", &x, &y, &z);
			mp[1LL*x*2000000005+y] = z;
			r[x] = x, c[y] = y;
		}
		
		int q; scanf("%d", &q);
		printf("Case #%d:\n", ++kase);
		
		while(q--)
		{
			int cmd, x, y;
			scanf("%d%d%d", &cmd, &x, &y);
			if(cmd == 1)
			{
				if(r.count(x) && r.count(y))
				{
					swap(r[x], r[y]);
				}
				if(!r.count(x) && !r.count(y))
				{
					r[x] = x, r[y] = y;
					swap(r[x], r[y]);
				}
			}
			else if(cmd == 2)
			{
				if(c.count(x) && c.count(y))
				{
					swap(c[x], c[y]);
				}
				if((!c.count(x) && !c.count(y)))
				{
					c[x] = x, c[y] = y;
					swap(c[x], c[y]);
				}
			}
			else
			{
				if(mp[1LL*r[x]*2000000005+c[y]] != 0)
				{
					printf("%d\n", mp[1LL*r[x]*2000000005+c[y]]);
				}
				else printf("0\n");
			}
		}
	}
	return 0;
}
twitter card validat 说:
2022年8月09日 10:06

Twitter Card validator obviously used in Twitter and to know more about the validator. It is merely important to understand about the Twitter Card. In this article, we will come up with details of Twitter Card and Twitter Card validator and different type of cards available to make you understand better along with its usage. twitter card validator Twitter Card goes gives a link between your tweets by adding designed structured look and attracting more audience. In simple terms, the code must add to webpage and when someone shares your tweets link will display as Twitter Card.

Alyssa 说:
2023年1月04日 21:39

We can virtualize an array memory space of 2*10^9 * 2*10^9 by initializing it to 0 and incrementing Cannabidiol For Arthritis some elements in this space from 1 to 5. This will help us to manage our memory more efficiently and avoid fragmentation.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter