| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
原来是忘初始化了,但也不能加个while(1)就过啊In Reply To:郁闷死了,关于judge的 Posted by:YouHaveWhatThing at 2008-09-08 19:31:06 > 下面这个程序,在check()函数的最后加上while(1)这个死循环就ac了,不加就wa了,用c++就OLE了,为什么啊
>
> #include <iostream>
> #include <string>
> #include <algorithm>
> using namespace std;
> #define REP(i,n) for(int i = 0;i < (n);++ i)
> #define FOR(i,s,n) for(int i = (s);i < (n);++ i)
> #define CLEAR(x) memset(x,0,sizeof(x))
> #define N 400
> int n,d,tot,a,b,mark;
> string w[N],tw[N];
> bool dfs(int i,int j,int no)
> {
> if(no > d) return 0;
> if(i == w[a].size() && j == w[b].size()) return 1;
> if(w[a][i] == w[b][j]) return dfs(i+1,j+1,no);
> bool ok = 0;
> if(w[a][i] == w[b][j+1] && w[a][i+1] == w[b][j]){
> swap(w[a][i],w[a][i+1]);
> ok |= dfs(i+1,j+1,no+1);
> swap(w[a][i],w[a][i+1]);
> }
> if(w[a][i] == w[b][j+1]) ok |= dfs(i,j+1,no+1);
> if(w[a][i+1] == w[b][j]) ok |= dfs(i+1,j,no+1);
> return ok || dfs(i+1,j+1,no+1);
> }
> bool check(int _i,int _j)
> {
> a = _i,b = _j;
> if(w[b].size() > w[a].size()) swap(a,b);
> if(w[a].size() - w[b].size() > d) return 0;
> if(w[a].size() - w[b].size() == d){
> int i,j,no;
> for(i = 0,j = 0,no = 0;i < w[a].size();i++,j++)
> while(w[a][i] != w[b][j] && i < w[a].size()) {
> i++,no++;
> if(no > d) return 0;
> }
> if(j < w[b].size()) return 0;
> return 1;
> }
> if(d == 1){
> int no = 0;
> REP(i,w[a].size()) if(w[a][i] != w[b][i]) no++;
> if(no <= 1) return 1;
> no = 0;
> REP(i,w[a].size()) if(w[a][i] != w[b][i]) {
> if(w[a][i+1] != w[b][i]) {
> w[a] = tw[a];
> return 0;
> }
> swap(w[a][i],w[a][i+1]),no++;
> }
> w[a] = tw[a];
> if(no <= 1) return 1;
> return 0;
> }
> if(d == 2){
> bool ok;
> if(w[a].size() - w[b].size() == 1){
> REP(i,w[a].size()){
> w[a].erase(i,1);
> if(dfs(0,0,1)) ok = 1;
> w[a] = tw[a];
> if(ok) return 1;
> }
> return 0;
> }
> ok = dfs(0,0,0);
> w[a] = tw[a];
> return ok;
> }
> while(1); //为什么加上这个死循环就ac,不加就wa
> }
> int main()
> {
> while(cin >> n >> d && n)
> {
> REP(i,n) cin >> w[i];
> sort(w,w+n);
> REP(i,n) tw[i] = w[i];
> tot = 0;
> REP(i,n) FOR(j,i+1,n) if(check(i,j)) cout << tw[i] << "," << tw[j] << endl,tot++;
> cout << tot << endl;
> }
> return 0;
> }
>
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator