SGU 238 Uncle Vasya and Bags for Potatoes 规律+构造

题目链接:点击打开链接

题意:

地上有n个背包,编号从1-n

下面n行第i行: 第一个数字表示背包i里有几个背包。

这样就得到了n个背包的一个状态。

问:有多少个背包状态可以通过一系列的操作达到输入的状态。

每步操作:

选取一个在地面上的背包a,然后把a背包内部的背包放到地上,把地上的放到a背包内部

思路:

我们可以把背包的嵌套关系 用一个图来表示。

就得到了一个森林,然后以地面为根把所有在地上的包相连,就得到了一棵树。

那么对于每次操作相当于换根操作。

所以一共有n-1个方法可以把根移动到其他地方。(画图模拟一下)

(1个背包时要特判)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
	int n, x, y;
	while (~scanf("%d", &n)) {
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &x);
			while (x -- > 0) {
				scanf("%d", &y);
			}
		}
		if (n == 1)
			puts("1");
		else
			printf("%d\n", n + 1);
	}
	return 0;
}
时间: 2024-11-08 11:20:04

SGU 238 Uncle Vasya and Bags for Potatoes 规律+构造的相关文章

sgu-238 Uncle Vasya and Bags for Potatoes

题目大意: 给你n个背包,然后输入n个数xi,表示第i个背包包含了多少个背包(目标状况).然后要你求有多少种初始情况可以达到目标状况. 解题思路: 显然对于这种包含关系我们很容易就想到了树上的关系,包含关系就是父亲与儿子的关系,然后在最外面的背包我们把他们都连在一个根节点上.然后一次操作就相当于找一棵子树.然后我们发现如果我们对同一个背包做两次操作相当于没有做,然后我们如果在初始状态上对地上的背包i做了一次操作,然后会发现地上只剩下i,j两个书包了,j是从i中拿出来的,这样我们就只能对j进行操作

Codeforces 837E Vasya&#39;s Function 数论 找规律

题意:定义F(a,0) = 0,F(a,b) = 1 + F(a,b - GCD(a,b).给定 x 和 y (<=1e12)求F(x,y). 题解:a=A*GCD(a,b) b=B*GCD(a,b),那么b-GCD(a,b) = (B-1)*GCD(a,b),如果此时A和B-1依然互质,那么GCD不变下一次还是要执行b-GCD(a,b).那么GCD什么时候才会变化呢?就是说找到一个最小的S,使得(B-S)%T=0其中T是a的任意一个因子.变形得到:B%T=S于是我们知道S=min(B%T).也

Vasya And Array CodeForces - 1187C (构造)

Vasya And Array 题意: 给你一个序列,再给你一些区间 t = 1时说明这些区间时非递减的 t = 0 时说明这些区间至少有一对数字 arr[i] > arr[i - 1] 思路: 只要左边的区间必然右边的区间大就好了 , 非递减区间中的数字都赋值为一样的数字 因为n只有1000 , 把初值cnt赋值为1e6 , 每次给区间赋值的时候 -1000 把第一种情况的区间赋值完成之后,剩下的还没有赋值的部分,都赋值为单调递减序列就可以了 1 #include<cstdio> 2

Codeforces Educational Codeforces Round 67

目录 Contest Info Solutions A. Stickers and Toys B. Letters Shop C. Vasya And Array D. Subarray Sorting E. Tree Painting Contest Info Data:2019.6.30 Solved:4/7 Solutions A. Stickers and Toys 题意: 有\(A\)物品\(s\)个,\(B\)物品\(t\)个,现在将这些物品装到\(n\)个箱子里,每个箱子只有一下三

Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red

hdu 1507 Uncle Tom&#39;s Inherited Land*(二分)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1853    Accepted Submission(s): 769 Special Judge Problem Description Your old uncle Tom inherited a piece of land fr

【SGU 390】Tickets (数位DP)

Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell tickets to the passengers. So no wonder that once upon a time in a faraway galaxy one conductor decided to diversify this occupation. Now this conductor

HDU 1507 Uncle Tom&#39;s Inherited Land*

Uncle Tom's Inherited Land* Special Judge Problem Description Your old uncle Tom inherited a piece of land from his great-great-uncle. Originally, the property had been in the shape of a rectangle. A long time ago, however, his great-great-uncle deci

ACM: SGU 101 Domino- 欧拉回路-并查集

sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Description Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The bl