Posted Updated Semprathlon / Simfae Dean a few seconds read (About 0 words)
具有肉眼可见的可用线段树解决的统计操作要求。
但是区间更新异常繁杂。
不要拘泥于区间内具体的数据选取,而应该采用状态转移。
除了向上传递操作以外,注意查询操作时不要把区段查询结果直接更新到左右子树上(覆盖区域并不一致)
1 | /** |
Time Limit: 2 Seconds Memory Limit: 65536 KB
Problem Description
There is a game very popular in ZJU at present, Bob didn’t meant to participate in it. But he decided to join it after discovering a lot of pretty girls playing it.
There are n stones on the ground and they are marked as 1 to n respectively. There will be 2 players in each competition. And the game rules are simple, A and B take turns to move. Each round, one of them can only take 1 number away, and then pick out all the divisors of the choosed number. When anyone who can not take away 1 number any longer, he will fail the whole game.Input
There are multiple cases. Each case include an integer number n (0 ≤ n ≤ 100).Output
For each case, A win, output “win”. If not, output”fail”.Sample Input
3
4Sample Output
win
win
乍一看是博弈,其实啥都没!问题中的决策不一定最优,只要求获胜的可能……
1 | import java.io.*; |
Time Limit: 2 Seconds Memory Limit: 65536 KB
Problem Description
Bob lives in an ancient village, where transactions are done by one item exchange with another. Bob is very clever and he knows what items will become more valuable later on. So, Bob has decided to do some business with villagers.
At first, Bob has N kinds of items indexed from 1 to N, and each item has Ai. There are M ways to exchanges items. For the ith way (Xi, Yi), Bob can exchange one Xith item to one Yith item, vice versa. Now Bob wants that his ith item has exactly Bi, and he wonders what the minimal times of transactions is.Input
There are multiple test cases.
For each test case: the first line contains two integers: N and M (1 < = N, M <= 100).
The next N lines contains two integers: Ai and Bi (1 < = Ai, Bi <= 10,000).
Following M lines contains two integers: Xi and Yi (1 < = Xi, Yi <= N).
There is one empty line between test cases.Output
For each test case output the minimal times of transactions. If Bob could not reach his goal, output -1 instead.Sample Input
2 1
1 2
2 1
1 24 2
1 3
2 1
3 2
2 3
1 2
3 4
- Sample Output
1-1
被这题的思维折腾哭了啊,从不可行的二分图,到搜索以及最短路径,再到乱七八糟的区间DP,不知多晚才拾起网络流……
伪最短路,RE
1 | import java.io.*; |
最小费用流,AC
1 | import java.io.BufferedInputStream; |
Time Limit: 5 Seconds Memory Limit: 32768 KB
Problem Description
James Cole is a convicted criminal living beneath a post-apocalyptic Philadelphia. Many years ago, the Earth’s surface had been contaminated by a virus so deadly that it forced the survivors to move underground. In the years that followed, scientists had engineered an imprecise form of time travel. To earn a pardon, Cole allows scientists to send him on dangerous missions to the past to collect information on the virus, thought to have been released by a terrorist organization known as the Army of the Twelve Monkeys.
The time travel is powerful so that sicentists can send Cole from year x[i] back to year y[i]. Eventually, Cole finds that Goines is the founder of the Army of the Twelve Monkeys, and set out in search of him. When they find and confront him, however, Goines denies any involvement with the viruscan. After that, Cole goes back and tells scientists what he knew. He wants to quit the mission to enjoy life. He wants to go back to the any year before current year, but scientists only allow him to use time travel once. In case of failure, Cole will find at least one route for backup. Please help him to calculate how many years he can go with at least two routes.Input
The input file contains multiple test cases.
The first line contains three integers n,m,q(1≤ n ≤ 50000, 1≤ m ≤ 50000, 1≤ q ≤ 50000), indicating the maximum year, the number of time travel path and the number of queries.
The following m lines contains two integers x,y(1≤ y ≤ x ≤ 50000) indicating Cole can travel from year x to year y.
The following q lines contains one integers p(1≤ p ≤ n) indicating the year Cole is at nowOutput
For each test case, you should output one line, contain a number which is the total number of the year Cole can go.Sample Input
9 3 3
9 1
6 1
4 1
6
7
2Sample Output
5
0
1Hint
6 can go back to 1 for two route. One is 6-1, the other is 6-7-8-9-1. 6 can go back to 2 for two route. One is 6-1-2, the other is 6-7-8-9-1-2.
多好的静态区间查询啊,可是不好好写O(n),写O(n^2)的就TLE。
1 | vector<pair<int,int> > vec; |
用线段树查询区间次小值也可行,但是从后往前处理跟方便,而且一次性完成。
1 | /** |
Time Limit: 2 Seconds Memory Limit: 65536 KB
- Problem Description
One day Leon finds a very classic game called Wumpus.The game is as follow.
Once an agent fell into a cave. The legend said that in this cave lived a kind of monster called Wumpus, and there were horrible pits which could lead to death everywhere. However, there were also a huge amount of gold in the cave. The agent must be careful and sensitive so that he could grab all of the gold and climb out of the cave safely.
The cave can be regarded as a n*n board. In each square there could be a Wumpus, a pit, a brick of gold, or nothing. The agent would be at position (0,0) at first and headed right.(As the picture below) For each step, there are six possible movements including going forward, turning left, turning right, shooting, grabbing the gold, and climbing out of the cave. If the agent steps into a square containing a pit or Wumpus, he will die. When the agent shoots, the Wumpus in front of him will die. The goal of the agent is to grab all of the gold and return to the starting position and climb out(it's OK if any Wumpus is still living).When a brick of gold is grabbed successfully, you will gain 1000 points. For each step you take, you will lose 10 points. Your job is to help him compute the highest point he can possibly get. For the purpose of simplification, we suppose that there is only one brick of gold and the agent cannot shoot the Wumpus. If there is a pit at (0, 0), the agent dies immediately. There will not be a Wumpus at (0, 0).Input
There are multiple cases. The first line will contain one integer k that indicates the number of cases.
For each case:
The first line will contain one integer n (n < = 20).
The following lines will contain three integers, each line shows a position of an object. The first one indicates the type of the object. 1 for Wumpus, 2 for pit and 3 for gold. Then the next two integers show the x and y coordinates of the object.
The input end with -1 -1 -1. (It is guaranteed that no two things appear in one position.)Output
The output contains one line with one integer, which is the highest point Leon could possibly get. If he cannot finish the game with a non-negative score, print “-1”.Sample Input
2
3
1 1 1
2 2 0
3 2 2
-1 -1 -1
3
1 1 1
3 2 2
-1 -1 -1Sample Output
850
870Hint
For the sample 1, the following steps are taken:
turn left, forward, forward, turn right, forward, forward, grab, turn left, turn left, forward, forward, turn left, forward, forward, climb.
There are in all 15 steps, so the final score is 840. For the sample 2 , the path is as follow:
一来一去的搜索……
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
1 | /** |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
用Trie做查询时,往死胡同里钻而且根本停不下来,啊啊啊啊……
1 |
|
这里的枚举倒是简洁得出奇。
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
下意识地做了贪心,果然被hack
计算期望,往往是从末状态到初状态倒推的,相见恨晚
1 |
|
特别拐弯抹角的平面几何模拟计算
1 |
|
1 | /** |
netflow,maxflow,Dinic
1 | /** |
特别复杂的套模板
Protest一时爽,final test全爆零 QwQ
1 | out.println(str.matches(".*w.*y.*h.*")||str.matches(".*v{2,}.*y.*h.*")?"Yes":"No"); |
偷懒着用正则表达式,华丽地TLE……
后来就醉了一样的胡乱的写了个匹配也不太行……
1 | import java.io.*; |
1 |
|
事实证明这并不是二分图匹配;并没有什么典型的算法让两个集合中的一个最大……
用DFS或BFS都可实现填色。
2014ACM/ICPC亚洲区北京站
Dire Wolf
1 | /** |
贪心真的是要贪婪死了。。。
已消除区段。。。其实对后续操作没有影响,符合无后效性。
贪心?走进死胡同了吧
1 | /** |