Link with Limit

题目链接

定义: f n ( x ) = f ( f n − 1 ( x ) ) f_n(x)=f(f_{n-1}(x)) fn(x)=f(fn1(x)),给定 f 1 ( x ) f_1(x) f1(x),现定义一函数 g ( x ) , g ( x ) = lim ⁡ n → ∞ 1 n ∑ i = 1 n f i ( x ) g(x),g(x)=\lim_{n \to \infty} {1 \over n}\sum_{i=1}^{n}{f_i(x)} g(x),g(x)=limnn1i=1nfi(x),问是否对于所有的 x x x,都有 x = g ( x ) x=g(x) x=g(x)

易知(反证)至少存在一个这样的集合,集合内的元素满足 f n ( x ) = y , f n − 1 ( y ) = z , f n − 2 ( z ) = x f_n(x)=y,f_{n-1}(y)=z,f_{n-2}(z)=x fn(x)=y,fn1(y)=z,fn2(z)=x这样的内部循环,而不再这种集合内的元素,也可以通过多次 f n ( x ) = f ( f n − 1 ( x ) ) f_n(x)=f(f_{n-1}(x)) fn(x)=f(fn1(x))关系与这些集合中的一个元素产生联系,当产生联系后, f n ( x ) = f ( f n − 1 ( x ) ) f_n(x)=f(f_{n-1}(x)) fn(x)=f(fn1(x))使得它的值在这个集合中循环,所以当 n → ∞ n \to \infty n时, g ( x ) , g ( x ) = lim ⁡ n → ∞ 1 n ∑ i = 1 n f i ( x ) = ∑ 对 应 集 合 的 所 有 元 素 之 和 对 应 集 合 的 元 素 个 数 g(x),g(x)=\lim_{n \to \infty} {1 \over n}\sum_{i=1}^{n}{f_i(x)}={\sum对应集合的所有元素之和 \over 对应集合的元素个数} g(x),g(x)=limnn1i=1nfi(x)=,所以如果满足所有 x = g ( x ) x=g(x) x=g(x),则所有集合的平均值相等

ps:注意精度问题, a b = c d ⇒ a ∗ d = b ∗ c {a \over b}={c \over d} \Rightarrow a*d = b*c ba=dcad=bc,采用乘法比较

AcCode:

//#pragma GCC optimize(2)
//#pragma comment(linker,"/STACK:1024000000,1024000000")

#include <iostream>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cmath>

#define pint std::pair<int,int>
#define in std::cin
#define out std::cout
#define SYNC std::ios::sync_with_stdio(false);

const int N = 2e5 + 10;

std::vector<pint> ans;
int cnt[N];
int edge[N];

inline void getAns(int rt, int sum, int num, int p) {
	if (rt == p)  ans.push_back(std::make_pair(sum, num));
	else getAns(edge[rt], sum + edge[rt], num + 1, p);
}

inline void dfs(int rt, int rem) {
	cnt[rt] = rem;
	if (cnt[edge[rt]] == rem) getAns(edge[rt], edge[rt], 1, rt);
	else if (cnt[edge[rt]] == 0) dfs(edge[rt], rem);
}

signed main() {
	SYNC;
	//std::ifstream in("input.txt");
	//std::ofstream out("out.txt", std::ios::out);
	//if (!in.is_open()) {
	//	std::cout << "error!" << std::endl;
	//	return 0;
	//}
	int t; in >> t;
	while (t--) {
		ans.clear();
		int n, rem = 0; in >> n;
		for (int i = 1; i <= n; i++)  cnt[i] = 0;
		for (int u = 1; u <= n; u++) { in >> edge[u]; if (u == edge[u]) rem++; }
		if (rem > 1) { out << "NO\n"; continue; }
		for (int i = 1, num = 1; i <= n; i++) if (!cnt[i]) dfs(i, num++);
		bool flag = true;
		for (int i = 0; i < ans.size() - 1; i++) if (ans[i].first * ans[i + 1].second != ans[i].second * ans[i + 1].first) { flag = false; break; }
		if (flag) out << "YES\n";
		else out << "NO\n";
	}
	//if (in.eof()) std::cout << "OK!\n";
	//in.close();
	//out.close();
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下的资源也很不错, 加减可以看一下o 使用C++制作戰車射擊-100%提供源码 http://download.csdn.net/source/2257663 使用C++制作3D动画人物-100%提供源码 http://download.csdn.net/source/2255453 Linux kernel 每一行都完全注释-初学者必备 http://download.csdn.net/source/1982431 Programming Embedded Systems 2nd http://download.csdn.net/source/1982338 J2ME pdf and code 郭克华 http://download.csdn.net/source/2229809 C语言程序设计(Visual+C 6.0环境) http://download.csdn.net/source/2232878 Visual C++ 60 MFC + code 学习最强宝典 http://download.csdn.net/source/2236266 ASP.NET Web (第一次亲密接触ASP.NET) http://download.csdn.net/source/2241466 1 Introduction 1-1 11 Motivation 1-1 12 Objective of the Specification 1-2 13 Scope of the Document1-2 14 USB Product Compliance1-2 15 Document Organization1-3 16 Design Goals1-3 17 Related Documents1-3 2 Terms and Abbreviations 2-1 3 USB 30 Architectural Overview 3-1 31 USB 30 System Description 3-1 311 USB 30 Physical Interface3-2 3111 USB 30 Mechanical3-2 312 USB 30 Power 3-3 313 USB 30 System Configuration3-3 314 USB 30 Architecture Summary3-3 32 SuperSpeed Architecture 3-4 321 Physical Layer 3-5 322 Link Layer 3-6 323 Protocol Layer3-7 324 Robustness3-8 3241 Error Detection 3-8 3242 Error Handling 3-9 325 SuperSpeed Power Management3-9 326 Devices3-10 3261 Peripheral Devices 3-10 3262 Hubs3-11 327 Hosts 3-12 328 Data Flow Models3-12 4 SuperSpeed Data Flow Model 4-1 41 Implementer Viewpoints 4-1 42 SuperSpeed Communication Flow4-1 421 Pipes4-2 43 SuperSpeed Protocol Overview 4-2 431 Differences from USB 204-2 4311 Comparing USB 20 and SuperSpeed Transactions4-3 4312 Introduction to SuperSpeed Packets4-4 44 Generalized Transfer Description4-4 441 Data Bursting4-5 442 IN Transfers4-5 443 OUT Transfers4-6 444 Power Management and Performance4-7 Universal Serial Bus 30 Specification, Revision 10 viii 445 Control Transfers4-8 4451 Control Transfer Packet Size 4-8 4452 Control Transfer Bandwidth Requirements 4-8 4453 Control Transfer Data Sequences4-9 446 Bulk Transfers4-9 4461 Bulk Transfer Data Packet Size 4-9 446
Internetworking IPv6 with Cisco Routers 想要学习IPv6的,这本书我觉得真的很好,希望大家都可以看看。 先贴一个目录给大家看看: Chapter 1: Introduction Overview, Why IPv6, Why a new address scheme, Best Effort: is it enough, Requisites to be satisfied by IPv6, An address space to last, To unify Intranets and the Internet, A good support for ATM, Plug and play, Mobility, Transition from IPv4 to IPv6, Choice criteria, The path toward standardization. Chapter 2: An overview on IPv6 Terminology, The Architecture of an IPv6 network, Addresses and names, Router and Internetworking, Layer 2 and layer 3 addresses, Neighbor Discovery, Encapsulation of IPv6 on LANs, Impact of IPv6 on upper layers, Modifications to sockets, Domain Name Service (DNS) modifications, DHCP servers. Chapter 3: IPv6 Headers The IPv6 header, Version, Priority, Flow Label, Payload Length, Next Header, Hop Limit, Source Address, Destination Address, Examples of IPv6 packets, Extension Header, Hop-by-Hop Option Header, The Jumbo Payload option, Routing Header, Fragment Header, The fragmentation process, Destination Options Header, Security Header, Size of IPv6 packets. Chapter 4: IPv6 Addresses The addressing space, Syntax of IPv6 addresses, Types of IPv6 addresses, The addressing model, Assignment of IPv6 addresses, Unicast Addresses, Anycast Addresses, Multicast Addresses, Pre-defined multicast Addresses, Addresses of an host, Addresses of a router. Chapter 5: ICMPv6 Protocol overview, Packets format. ICMP messages transmission, Destination unreachable, Packet too big, Time exceeded, Parameter problems, Echo request, Echo response, Group membership, Router Solicitation, Router Advertisement, Neighbor Solicitation, Neighbor Advertisement, Redirect, Options format, Link Layer Address Source/Target Option, Information on Prefixes Option, Redirect Header, MTU Option. Chapter 6: Neighbor Discovery Link types, Neighbor Discovery service, Router and prefix discovery, The address resolution, Redirect function, Data structures of an host, Neighbor Cache, Destination Cache, Prefix List, Default Router List, An example of cache, Transmission algorithm of a packet, Neighbor Unreachability Detection, Address Autoconfiguration, Stateless autoconfiguration, DHCPv6 and the stateful autoconfiguration, Duplicate Address Detection, IPv6 on Ethernet. Chapter 7: The Routing in Ipv6 Network model, Routing algorithms, Static Routing, Metrics, Distance vector, Path vector, Link state, Redistribution, Multi-protocol routing, RIPv6, OSPFv6, IDRPv6, BGP4+, Relations between addressing and routing, Internet structure, Multihomed routing domains, Tunnels, Private links, Multicast Routing, Intranets. Chapter 8: Security in IPv6 Security functions, Authentication Header (AH), Authentication methodology, Encrypted Security Payload (ESP), Encryption keys distribution, Manual keys distribution, Automatic keys distribution, Applications of IPv6 security functions, Private Virtual Networks, Application Layer security, Routing security. Chapter 9: IPv6 on ATM LLC/SNAP encapsulation, VC multiplexing, AAL 5, Neighbor Discovery, Addresses Auto-configuration, ICMP Redirect, MARS (Multicast Address Resolution Server), NHRP (Next Hop Resolution Protocol), Alternative approaches, IP Switching, Tag Switching. Chapter 10: The mobility in Ipv6 Mobility problems, Introduction to host mobility in IPv6, Examples of operation of a mobile host in IPv6, Binding Update option, Binding Acknowledgment option, Binding Request option, Characteristics of nodes, Routers Requisites, Mobile nodes Requisites, Transmission of packets to a mobile node, Mobility detection, Multicast traffic handling, At home again. Chapter 11: IPv6 and multimedia traffic Introduction, Integrated Services model, Coding of multimedia information, Reference Implementation, Traffic control, Packet scheduler, Buffers management, Packets classification, Access control, RSVP, Flowspec and Filterspec, Reservation styles, The Soft State Approach, Reservations and routing, Integrated Services in an IP over ATM architecture. Chapter 12: The migration from IPv4 to IPv6 Tunneling, Alternative tunneling schemes, IPv6 Addresses with Embedded IPv4 Addresses, MTU, Hop Limit, Default configured tunnel, Dual Stack Approach, The 6bone, The 6bone node at Cisco Systems, Registration to RIPE-NCC. Chapter 13: Cisco Systems and IPv6 Cisco Systems, the premier IP vendor, is committed to the evolution of the Internet/Intranets and considers the next generation IP to be a key component of their growth. It has taken a leadership role in both the definition and implementation of the IPv6 protocols within the IETF and within its IOSTM software. This chapter describes the approach of Cisco System to IPv6 and how IPv6 is integrated in IOS. It contains an example of a 6bone backbone node running IPv6 on a Cisco router, with the IOSTM configuration file, the explanation of principal IPv6 IOSTM commands, the addressing plan and additional features, suvh as BGP4+ and NAT. Appendix A: Excerpts from RFC Routing header: pseudo code, Example of Routing header processing, Processing of ICMPv6 packets, Addresses to be used during the testing phase, MTU of a tunnel and fragmentation, Transmission of IP packets. Appendix B: Analysis of IPv6 packets This appendix contains example of decoding of IPv6 packets using a Radcom RC-100 WL protocol analyzer. Decoded packets are TCP, UDP, Router Solicitation, Router Advertisement, Neighbor Solicitation, Neighbor Advertisement Packets. Appendix C: How to receive more information Author's address, Author's WWW address, Mailing list, Where you can find RFCs and Internet Drafts, The Playground server, The 6bone, Other WWW servers. Appendix D: Glossary

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值