1.写出下面题目的程序代码(C++) 并且输入输出都截个 谢谢~
2.poj 3278
3.å¦ä½å»ºç«online judgeç³»ç»
写出下面题目的程序代码(C++) 并且输入输出都截个 谢谢~
//记的以前学校时写过,好像是新盈彩源码POJ的题目。源代码还在电脑上留着,nimble源码下载仅供参考
#include <iostream>
#include <cmath>
using namespace std;
const int MAXN = ;
const int MAXM = ;
const int MAXP = ;
const int MAXT = 6;
struct Tpoint {
int x,php源码 直播 y;
};
Tpoint u[MAXN],v[MAXN],w[MAXN],p[MAXN];
int step[4][2] = { { 0,1}, { 0,-1}, { 1,0}, { -1,0}};
int mark[MAXM][MAXM], map[MAXP][MAXP], board[MAXT][MAXT];
int num, cnt, ver, size;
bool cover[MAXM][MAXM];
char line[MAXM][MAXM];
//判断B集合中的连通性
inline int connect(int x, int y)
{
int front = 0, rear = 1;
w[rear].x = x; w[rear].y = y; board[x][y] = 0;
while(front < rear) {
front ++;
for(int i = 0; i < 4; i ++) {
int tx = w[front].x + step[i][0];
int ty = w[front].y + step[i][1];
if(tx >= 0 && tx < size && ty >= 0 && ty < size && board[tx][ty]) {
board[tx][ty] = 0;
rear++;
w[rear].x = tx;
w[rear].y = ty;
}
}
}
return rear;
}
//通过平移判断两个集合是否刚好构成N*N的图形
inline bool match(int minx2, int miny2, int maxx2, int maxy2, int maxx1, int maxy1)
{
for(int i = maxx2 - size + 1; i < minx2 + size - maxx1; i ++) {
for(int j = maxy2 - size + 1; j < miny2 + size - maxy1; j ++) {
bool flag = true;
for(int k = 0; k < num; k ++) {
if(map[v[k].x+i][v[k].y+j]) {
flag = false;
break;
}
}
if(flag) return true; //集合A和集合B刚好能组成size*size的正方形,返回true;
}
}
return false;
}
inline bool ok(int minx2,gsp系统源码 int miny2, int maxx2, int maxy2) //参数传递集合A的边界
{
int i, j, minx1, miny1, maxx1, maxy1;
minx1 = miny1 = ; maxx1 = maxy1 = 0;
for(i = 0; i < ver; i ++) {
if(! cover[p[i].x][p[i].y]) { //标记集合B的边界
if(minx1 > p[i].x) minx1 = p[i].x;
if(miny1 > p[i].y) miny1 = p[i].y;
if(maxx1 < p[i].x) maxx1 = p[i].x;
if(maxy1 < p[i].y) maxy1 = p[i].y;
}
}
num = 0;
memset(map, 0, sizeof(map));
for(i = 0; i < ver; i ++) {
if(! cover[p[i].x][p[i].y]) {
if((p[i].x - minx1 >= size) || (p[i].y - miny1 >= size))
return false;
//集合B的边界超过size*size,返回false
v[num].x = p[i].x - minx1; //将集合B往左上角移
v[num].y = p[i].y - miny1;
num ++;
}else {
map[p[i].x - minx2 + 5][p[i].y - miny2 + 5]=1; //将集合A往右下角移
}
}
memset(board,建材cms源码 0, sizeof(board));
for(i = 0; i < num; i ++)
board[v[i].x][v[i].y] = 1;
if(connect(v[0].x,v[0].y)<num) return false; //集合B不连通返回false
maxx2 = maxx2 - minx2 + 5; maxy2 = maxy2 - miny2 + 5;
minx2 = miny2 = 5;
maxx1 = maxx1 - minx1; maxy1 = maxy1 - miny1;
minx1 = miny1 = 0;
for(i = 0; i < 4; i ++) { //4次旋转
if(match(minx2, miny2, maxx2, maxy2, maxx1, maxy1))
//集合A与B刚好能够组成size*size的正方形,返回true
return true;
minx1 = miny1 = INT_MAX; maxx1 = maxy1 = INT_MIN;
for(j = 0; j < num; j ++) {
int temp = v[j].y;
v[j].y = size - v[j].x - 1;
v[j].x = temp;
if(minx1 > v[j].x) minx1 = v[j].x;
if(miny1 > v[j].y) miny1 = v[j].y;
if(maxx1 < v[j].x) maxx1 = v[j].x;
if(maxy1 < v[j].y) maxy1 = v[j].y;
}
for(j = 0; j < num; j ++) {
v[j].x -= minx1; v[j].y -= miny1; //将集合B往左上角移
}
maxx1 -= minx1;maxy1 -= miny1;
}
return false;
}
inline bool dfs(int minx, int miny, int maxx, int maxy, int m, int k)
{
if(k > m) return false;
if(dfs(minx, miny, maxx, maxy, m, k + 1)) return true; //k点不属于集合A
if(abs(u[k].x - minx) >= size || abs(u[k].y - miny) >= size ||
abs(u[k].x - maxx) >= size || abs(u[k].y - maxy) >= size)
//若集合A超过边界size,则返回false
return false;
int i, tx, ty;
for(i = 0; i < 4; i ++) {
tx = u[k].x + step[i][0];
ty = u[k].y + step[i][1];
if(line[tx][ty] == '*' && ! mark[tx][ty]) { //可扩展点进行标记
m ++;
u[m].x = tx;
u[m].y = ty;
mark[tx][ty] = k;
}
}
cover[u[k].x][u[k].y] = true;
if(ok(__min(minx, u[k].x), __min(miny, u[k].y), __max(maxx, u[k].x), __max(maxy, u[k].y)))
//若刚好能组成size*size的正方形,则返回true
return true;
if(dfs(__min(minx, u[k].x), __min(miny, u[k].y), __max(maxx, u[k].x), __max(maxy,u[k].y), m, k + 1))//继续搜索集合A,若成功返回true
return true;
cover[u[k].x][u[k].y] = false;
for(i = 0; i < 4; i ++) {
tx = u[k].x + step[i][0];
ty = u[k].y + step[i][1];
if(mark[tx][ty] == k) mark[tx][ty] = 0; //消除标记
}
return false;
}
int main()
{
cnt = 0;
while(gets(line[cnt++])); //读入数据
ver = 0;
for(int i = 0; i < cnt; i ++)
for(int j = 0; line[i][j]; j ++)
if(line[i][j] == '*') {
p[ver].x = i; p[ver].y = j; ver ++;
}
size = (int)sqrt((double)ver); //正方形的边长为size
memset(cover, false, sizeof(cover));
memset(mark, 0, sizeof(mark));
u[1].x = p[0].x; u[1].y = p[0].y;
mark[u[1].x][u[1].y] = -1;
dfs(u[1].x, u[1].y, u[1].x, u[1].y, 1, 1); //搜索集合A的可能情况
for(i = 0; i < cnt; i ++) {
for(int j = 0; line[i][j]; j ++) {
if(line[i][j]=='*') {
if(cover[i][j]) printf("A");
else printf("B");
}else printf(".");
}
printf("\n");
}
return(0);
}
poj
Accepted K MS Pascal B -- ::
æºä»£ç ï¼ä½ å¯ä»¥å æ交ä¸æ¬¡è¯è¯ï¼è¿æ¯ACçï¼ä¸æ¯å§ç
program p;
var
q,step:array[0..] of longint;
visit:array[0..] of boolean;
head,tail,n,k,maxn,tmp:longint;
begin
readln(n,k);
if n>=k then writeln(n-k)
else
begin
fillchar(visit,sizeof(visit),false);
q[0]:=n; visit[n]:=true; step[0]:=0;
head:=0; tail:=0; maxn:=k*2;
while (head<=tail) do
begin
tmp:=q[head]*2;
if (tmp<maxn) and (not visit[tmp]) then
begin
inc(tail); visit[tmp]:=true;
q[tail]:=tmp; step[tail]:=step[head]+1;
if (visit[k]) then break;
end;
tmp:=q[head]-1;
if (tmp>=0) and (not visit[tmp]) then
begin
inc(tail); visit[tmp]:=true;
q[tail]:=tmp; step[tail]:=step[head]+1;
if (visit[k]) then break;
end;
tmp:=q[head]+1;
if (tmp<maxn) and (not visit[tmp]) then
begin
inc(tail); visit[tmp]:=true;
q[tail]:=tmp; step[tail]:=step[head]+1;
if (visit[k]) then break;
end;
inc(head);
end;
writeln(step[tail]);
end;
end.
æ¹æ³ï¼ä¸»è¦ç®æ³æ¯å¹¿åº¦ä¼å æç´¢ãå 讨论nåkï¼n大äºçäºkæ¶ï¼åªè½ååéæä¸ç¨å¨ï¼å³ç´æ¥è¾åºç»æï¼ç¶åç¨å¹¿æ解å³nå°äºkçæ åµï¼ä»nå¼å§æç´¢ï¼å³æ¯æ¬¡ååä¸ä¸ªä½ç½®ï¼ä¸ä¸ä¸ªä½ç½®ï¼åå½å2åä½ç½®æç´¢ï¼æ¯æ¬¡æç´¢å°æ°çä½ç½®è®°å½å½åä½ç½®ï¼qæ°ç»çä½ç¨ï¼åèµ°å°å½åä½ç½®æéæ¥æ°ï¼stepæ°ç»çä½ç¨ï¼å¹¶è®°å½è¯¥ç¹å·²ç»èµ°è¿ï¼visitæ°ç»çä½ç¨ï¼ï¼æç´¢è¿çä¸ç¨åæï¼æå°kæ¶è¾åºç»æ并éåºç¨åºã注æçæ¯Farmer Johnæ éèµ°å°å¤§äºçäº2*kçç¹ï¼å 为走å°è¿æ ·çç¹ä¸è¿ä¸å¦ç´æ¥ä¸ç´ååèµ°çæ¥æ°å°ã
ååå®é¥ï¼è个水é¢ï¼è¿é¢æ¯æ åç广æé¢
2年没ç¨Pascaläº...æç¹æ念ä»åäº
NOIPï¼NOIï¼ å æ²¹ï¼ï¼ï¼
å¦ä½å»ºç«online judgeç³»ç»
èæ主æºåè½æéï¼ä¸å¯è½è¿è¡online judgeç³»ç»ï¼å·¥ä½åçï¼ç¨æ·æ交ç¨åºæºç --->Webç½ç«æå¡å¨--->转åç»ç¨äºç¼è¯è¿è¡è¯æµç¨æ·ç¨åºçæå¡å¨--->å°ç»æè¿åWebç½ç«æå¡å¨-->è¿åç»ç¨æ·éå¶å ç´ ï¼1ã硬件ï¼(1)èæ主æºæä¾ç»ç¨æ·ï¼ç½ç«å¶ä½è ï¼çæéæå°ï¼ä¸è½èªä¸»å®è£ æå¡å¨ç«¯è½¯ä»¶ï¼æ æ³æ建è¯æµå¹³å°ã(2)è¯æµæå¡å¨éè¦æå¾å¼ºçæ§è½ï¼å¦åæ æ³æ»¡è¶³å¤ç¨æ·åæ¶ç¼è¯è¿è¡è¯æµ(èæ主æºä¸å¯è½è¾¾å°)ãè´ä¹°ï¼ç§ç¨ï¼æå¡å¨è´¹ç¨æè´µ2ã软件ï¼å建ç«ç½ç«ç¸æ¯ï¼éè¦èªå·±é¢å¤ç¼åæå¡å¨é´åè°è½¯ä»¶åè¯æµç¨åºãå ¶ç¼ç¨è½ååç»éªè¦æ±å¾é«ã