| 立即激活博客秀 |
|
用户名:bdfzoi 笔名:bdfzoi 地区: |
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
北大附中信息学奥赛战队 QQ_GRUOP: #7375712
zt: 小议竞赛的准备和考试技巧 by HQM
和汤洋的聊天记录,让我长进了不少
好久没写 blog 了
第一个 AC 的二分图题
我晕......
这两天做pku warm up,发现一个叫NPHard的巨强,正奇怪那里出来这么一个强人,结果突然之间发现......
我不说了,大家自己去看
http://acm.pku.edu.cn/JudgeOnline/problemstatus?problem_id=2171
http://acm.pku.edu.cn/JudgeOnline/problemstatus?problem_id=2172
http://acm.pku.edu.cn/JudgeOnline/problemstatus?problem_id=2173
还有很多......
那个NPHard的代码总是跟一个人一样长......
那个人就是......
^_^
今天的pku巨happy
先是看nba,火箭加时输国王,然后巨郁闷,开始做题,这时12:30。
最先看G,DP,5分钟就写完了,一交,CE......原来是忘了把include那行考上了,重交一次,ac......
然后看H,想了一个算法,O(N^2),虽然肯定到不了,但还是没把握,于是看I,巨easy的模拟题,写完代码,一次ac.然后回到H,发现Status里没有tle的,于是坚定信心,写了一个,一交,果然ac。这时才1:00
然后我就开始犹豫,是接着做还是算了,后来读了F,基本感觉是做不出来的,虽然很显然的是要用Hash,但我从来没实践过。就这样犹豫了一会,最终还是决定试一下。于是按照记忆中的方法,写了个线性探察判重的hash,最happy的是,只调了一次就通过样例,然后上去一交,居然ac......
然后兴奋不已的我就去打球了,一打发现球感巨好,看来OI真是一好东西呀......
郁闷死了
PKU warm up 2 的Problem B,虽然最后终于过了,但弄的我心情很糟......然后就再也没有心情编下面的题了......
今天看了一道题,感觉不错,虽然没想到算法......
大家看看吧,谁能帮我想想,谢谢了
PKU 1944
Fiber Communications
Description
Farmer John wants to connect his N (1 <= N <= 1,000) barns (numbered 1..N) with a new fiber-optic network. However, the barns are located in a circle around the edge of a large pond, so he can only connect pairs of adjacent barns. The circular configuration means that barn N is adjacent to barn 1.
FJ doesn't need to connect all the barns, though, since only certain pairs of cows wish to communicate with each other. He wants to construct as few
connections as possible while still enabling all of these pairs to communicate through the network. Given the list of barns that wish to communicate with each other, determine the minimum number of lines that must be laid. To communicate from barn 1 to barn 3, lines must be laid from barn 1 to barn 2 and also from barn 2 to barn 3(or just from barn 3 to 1,if n=3).
Input
* Line 1: Two integers, N and P (the number of communication pairs, 1 <= P <= 10,000)
* Lines 2..P+1: two integers describing a pair of barns between which communication is desired. No pair is duplicated in the list.
Output
One line with a single integer which is the minimum number of direct connections FJ needs to make.
Sample Input
5 2
1 3
4 5
5 2 1 3 4 5
Sample Output
3
3
Hint
[Which connect barn pairs 1-2, 2-3, and 4-5.]
Source
USACO 2002 February
麻烦tN看一下我1008的代码
秦腾写了一个栈搜索,怕被BS 现在yz, ls, wd都写栈搜索, 就我一个人用咱们那种dfs
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#define bool int
#define true 1
#define false 0
#define MAXN 5
ifstream fin("d:/in.txt");
#define cin fin
enum {TOP = 0, LEFT = 1, BOTTOM = 2, RIGHT = 3};
int n;
bool used[MAXN*MAXN];
int t[MAXN][MAXN];
int a[MAXN*MAXN][4];
bool found;
int w;
bool tlink[26][26], blink[26][26], llink[26][26], rlink[26][26];
bool check(int x, int y) {
if (x == 0 && y == 0)
return true;
else if (x == 0 && y != 0) {
return (a[t[0][y]][TOP] == a[t[0][y-1]][BOTTOM]);
}
else if (y == 0 && x != 0) {
return (a[t[x][0]][LEFT] == a[t[x-1][0]][RIGHT]);
}
else {
return (a[t[x][y]][TOP] == a[t[x][y-1]][BOTTOM]) && (a[t[x][y]][LEFT] == a[t[x-1][y]][RIGHT]);
}
}
void dfs(int x, int y) {
int i, j, k;
if (found)
return;
if (x == n) {
dfs(0, y+1);
return;
}
if (y >= n) {
found = true;
return;
}
for (j = 0; j < n*n && !found; j++)
if (!used[j]) {
used[j] = true;
/*for (k = 0; k < 4; k++)
t[x][y][k] = a[j][k];*/
t[x][y] = j;
if (check(x,y))
dfs(x+1, y);
used[j] = false;
}
}
void for_each() {
int i, j, k1, k2, m;
memset(used, 0, sizeof(used));
memset(t, 0, sizeof(t));
cin >> n;
if (cin.eof() || n == 0)
exit(0);
for (i = 0; i < n*n; i++) {
for (j = 0; j < 4; j++)
cin >> a[i][j];
}
cout << "Game " << w << ":" << endl;
for (i = 0; i < n*n; i++)
for (j = 0; j < n*n; j++) {
llink[i][j] = (a[i][LEFT] == a[j][RIGHT]);
rlink[i][j] = (a[i][RIGHT] == a[j][LEFT]);
tlink[i][j] = (a[i][TOP] == a[j][BOTTOM]);
blink[i][j] = (a[i][BOTTOM] == a[j][TOP]);
}
found = false;
dfs(0, 0);
cout << (found ? "Possible" : "Impossible") << endl;
cout << endl;
}
int main() {
w = 1;
while (1) {
for_each();
w++;
}
}