分类目录归档:贡献计数法

[bzoj 2563] 阿狸和桃子的游戏

Description

  阿狸和桃子正在玩一个游戏,游戏是在一个带权图G=(V, E)上进行的,设节点权值为w(v),边权为c(e)。游戏规则是这样的:
  1. 阿狸和桃子轮流将图中的顶点染色,阿狸会将顶点染成红色,桃子会将顶点染成粉色。已经被染过色的点不能再染了,而且每一轮都必须给一个且仅一个顶点染色。
2. 为了保证公平性,节点的个数N为偶数。
3. 经过N/2轮游戏之后,两人都得到了一个顶点集合。对于顶点集合S,得分计算方式为

由于阿狸石头剪子布输给了桃子,所以桃子先染色。两人都想要使自己的分数比对方多,且多得越多越好。如果两人都是采用最优策略的,求最终桃子的分数减去阿狸的分数。

继续阅读

AIO2010 Solution

Ninjas

You used to like ninjas. That was before the shadowy shiro-obi ninja clan moved in next door. They're mostly decent neighbours - they keep to themselves and never throw loud parties - but every few nights they sneak into your house and raid the kitchen. With no one else to turn to, you decide to take matters into your own hands and catch them in the act.

There are N ninjas trying to get inside, one at a time. You wait and watch carefully, grabbing the first one who comes past. However, in the time it takes you to securely tie up this first ninja, K other ninjas manage to sneak past you. Nevertheless, you persevere, grabbing the next ninja. Again, while you tie them up, K more ninjas sneak past. This continues until all of the ninjas have tried to get in.

\includegraphics[width=15cm]{ninjaexample}

In the above example, K=2. That is, for each ninja you tie up, the following two ninjas will sneak past. You catch the first ninja who comes past, and then ninjas #2 and #3 sneak past you. You catch ninja #4, and then ninjas #5 and #6 sneak past you. This repeats until all N ninjas have either been caught or have snuck past you.

Your task is to write a program that reads in the values of N and K, and calculates the number of ninjas who sneak past you.

继续阅读

AIO2011 Solution

Pirates

Yarr! Welcome aboard the Black Pearl! I'm Captain Mia Swamp, and this is my First Matey, Growlybills. We've heard you're handy with these computing contraptions, so I'll make you a deal: help us out with a little problem, and we won't feed you to the sharks.

You're in? Thought so.

\includegraphics[width=10cm]{map_meta}

See that map yonder? That long, thin island there is the Isle of Obstaclewick. Boring place. All you need to know is that it's L nautical miles long from east to west, and so thin we all just say it has zero width.

Our ship, the Black Pearl, is sailing the north coast of the island, X nautical miles from the west point. See the other ship, the one sailing the south coast, Y nautical miles from the west point? That's the HMS Smallerout, our target. It may look like a wibbly-wobbly old thing, but it's carrying some of Britain's greatest treasures.

We can sail either way around the Isle of Obstaclewick, approaching the Smallerout from either side. What we want you to do is tell us which way is shorter. We don't want to overwork the... volunteers... in the galley. So that's your job, landlubber! Write us a program that calculates the shortest distance we have to sail to reach the Smallerout!

继续阅读