Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: Each fox is sitting at some table…
大意: n只狐狸, 要求分成若干个环, 每个环的狐狸不少于三只, 相邻狐狸年龄和为素数. 狐狸年龄都>=2, 那么素数一定为奇数, 相邻必须是一奇一偶, 也就是一个二分图, 源点向奇数点连容量为2的边, 偶数点向汇点连容量为2的边, 和为偶数的奇数点向偶数点连容量为1的边, 看能否满流即可. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #inc…
E. Fox And Dinner time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai year…
CF510E. Fox And Dinner https://codeforces.com/contest/510 分析: 由于\(a_i>2\), 相邻两个数一定一奇一偶,按奇偶建立二分图. 环上每个点度数都为2,因此只需要找是否每个点都能匹配两个. 建图跑dinic即可. 代码: #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include…
题目链接 给出n个人, 以及每个人的值, 要求他们坐在一些桌子上面, 每个桌子如果有人坐, 就必须做3个人以上. 并且相邻的两个人的值加起来必须是素数.每个人的值都>=2. 由大于等于2这个条件, 可以知道素数都是奇数, 那么很明显就需要一奇一偶相邻这样做, 那么一个桌子上必定有偶数个人. 一个奇数旁边有两个偶数, 一个偶数旁边有两个奇数. 所以可以先判断n是否为偶数, 如果是奇数直接输出不可能. 然后开始奇偶建边, 源点和奇数建边, 权值为2, 因为一个奇数需要和两个偶数匹配: 偶数和汇点建边…
Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: Each fox is sitting at some table…
网络流. 原点到偶数连边,容量为2, 奇数到汇点连边,容量为2, 偶数到与之能凑成素数的奇数连边,容量为1 如果奇数个数不等于偶数个数,输出不可能 如果原点到偶数的边不满流,输出不可能 剩下的情况有解:因为一个偶数点选了两个奇数点,一个奇数点被两个偶数点选择,一定能构造出环. #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #…
题目链接:http://codeforces.com/problemset/problem/510/E 乍一看和那啥魔术球问题有点神似啊/XD 其实是不一样的. 解决这道问题的关键在于发现若是相邻的两个数的和是质数,那么他们必定是一奇一偶! 而且一个奇数旁边一定是两个偶数,一个偶数旁边一定是两个奇数(因为是一个大于$3$的环) 秒啊!这就变成了匹配模型. 源点向所有值为奇数的点连容量为$2$边,值为奇数的点向所有与它的和为质数的且值为偶数点连容量为$1$边,所有值为偶数的点向汇点连容量为$2$的…
[解析]欧拉筛法,奇偶分析.建二分图,网络流 [Analysis] http://blog.csdn.net/qq574857122/article/details/43453087. 所谓的连通块就是指满流了,因为我直接使用剩余流量求网络流. 至于怎样推断满流,我想到下面几种: ①对于初始的网络.若图的流向是一样的.那么就直接推断对于一条边k的正向边k>>1<<1是否满流. ②对于一般的,能够存流量限制. ③或者对每条边再存个tag.若tag=1,则表示初始时这条边容量限制非0,…
而是Div2的最后一题,当时打比赛的时候还不会最大流.自己能够把它写出来然后1A还是很开心的. 题意: 有n个不小于2的整数,现在要把他们分成若干个圈.在每个圈中,数字的个数不少于3个,而且相邻的两个数之和是质数. 分析: 因为每个数都不小于2,所以相加得到的质数一定是奇数,那么在某个圈中,一定是奇偶相间的. 也就是 奇数相邻的两个数是偶数,偶数相邻的两个数是奇数. 所以一个圈中的数字一定是偶数个,所有的输入中也必须是偶数和奇数的个数相同才可能有解. 这转化为了二分图匹配,其中X是奇数,Y是偶数…
\(\mathcal{Description}\)   Link.   给定正整数集合 \(\{a_n\}\),求一种把这些数放置在任意多个圆环上的方案,使得每个环的大小大于 \(2\) 且环上相邻两数之和是素数.   \(n\le200\),\(2\le a_i\le10^4\). \(\mathcal{Solution}\)   这题怎么也黑了呢 qwq--   考虑到 \(2\le a_i\),有 \(4\le a_i+a_j\),所以素数必然是奇素数,而一个环必然是偶环.一个常见的套路是…
题目:http://codeforces.com/contest/512/problem/C 题目大意:给你若干个数,让你分成k组,每组围成一个圆,使得相邻两个数和均为素数,且每组人数应>=3个.输出方案 分析:不容易想到最大流. 官方解答: 因为每个数都>=2,所以素数一定是由一个奇数+一个偶数,即一个奇数两边的必须为偶数,一个偶数的周围的必须是奇数. 于是考虑: 若一个奇数和一个偶数的和为素数,那么在它们之间连上双向边,权值为1 因为每个奇数要连两个偶数,每个偶数要连两个奇数,所以可以弄个…
Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards…
可以用网络流解决这个题. 注意到\(a_i \geqslant 2\),所以当相邻数字要和为质数时,这两个数要一个为奇数,一个为偶数. 所以就先将所有数按奇偶分为两列,其就构成了一个二分图,二分图中和为质数的两个数间连容量为\(1\)的边,表示只能匹配一次. 因为是圆桌,所以一个数要恰好匹配两个数,所以每个点在和源汇点连边时,容量要为\(2\),同时这也保证了每个圆桌中至少有\(3\)个狐狸. 无解的情况就是二分图两个部分大小不是都为\(\frac{n}{2}\)或最大流的结果不为\(n\).…
Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of n vertices and m edges. Vertices are numbered from 1 to n. Vert…
In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighb…
如果要相邻两个数(a[i] >= 2)相加为质数,显然它们的奇偶性不同,也就是说一个圆桌(环)必须是偶环. 也就是答案的若干个环组成了一张二分图,其中以奇偶分色. 考虑每个点的度数一定为2,用最大流解决: 让源点向所有的奇数点连流量为2的边. 让所有的偶数点向汇点连流量为2的边. 当且仅当一组奇数和偶数相加为质数时,连一条流量为1的边. 可以证明,如果最大流小于n,那就不存在解,否则一定存在若干个边数大于2的偶环,使得所有点只出现在一个环里,最后Dfs找出环即可. $ \bigodot $ 技巧…
近日好不容易在自救之路写完暑训遗留下来的网络流8题,在此回顾一下. Going Home POJ - 2195 题意:m要去H,一个H只能容纳一个m,一步一块钱,问最小花费. 思路:最小费用最大流的板子题.有博客用了Dijkstra,不过在我看来,存在负权边的图是不能使用Dijkstra的,所以虽然我曾立誓再也不写SPFA,现在也不得不屈服了. #include<iostream> #include<algorithm> #include<vector> #includ…
Fox And Jumping CodeForces - 510D Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0. There are also n cards, each card…
B. Dinner with Emma 题目连接: http://www.codeforces.com/contest/616/problem/A Description Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefer…
D. Fox And Jumping 题目连接: http://codeforces.com/contest/510/problem/D Description Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at…
C. Fox And Names 题目连接: http://codeforces.com/contest/510/problem/C Description Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in…
B. Fox And Two Dots 题目连接: http://codeforces.com/contest/510/problem/B Description Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this: Each cell contains a dot that ha…
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A sna…
Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description A group of k students from Cooking University living in the campus decided that each day of the semester one of them will p…
题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.…
题意 现在有m个人,每一个人都特别喜欢狗.另外还有一棵n个节点的树. 现在每个人都想要从树上的某个节点走到另外一个节点,且满足要么这个人自带一条狗m,要么他经过的所有边h上都有一条狗. 2<=n<=2*10^4,1<=m<=10^4 输入格式 第一行为两个整数n,m,分别表示树的大小和人数. 接下来有n-1行,每一行有两个整数u,v,表示书上有一条u-v的边. 再接下来有m行,每一行两个整数x[i],y[i]表示第i个人想从x[i]走到y[i]. 输出格式 第一行为一个整数k,表示…
题意 给你 \(n\) 个武器,\(m\) 个敌人,问你最多消灭多少个敌人,并输出方案. 总共有三种武器. SQL 火箭 - 能消灭给你集合中的一个敌人 \(\sum |S| \le 100000\) : 认知光束 - 可以消灭 \([l, r]\) 区间中的一个敌人: OMG 火箭筒 - 消灭给你集合中的 \(0\) 个或者 \(2\) 个敌人,集合大小为 \(3\) ,且火箭筒消灭的集合互不重合. \(n, m \le 5000\) . 题解 现场的时候直觉告诉我是网络流,但是这个数据范围,…
C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns…
B. Fox and Minimal path 题目连接: http://codeforces.com/contest/388/problem/B Description Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You…