1.å¦ä½å»ºç«online judgeç³»ç»
2.写出下面题目的程序代码(C++) 并且输入输出都截个图 谢谢~
å¦ä½å»ºç«online judgeç³»ç»
èæ主æºåè½æéï¼ä¸å¯è½è¿è¡online judgeç³»ç»ï¼å·¥ä½åçï¼ç¨æ·æ交ç¨åºæºç --->Webç½ç«æå¡å¨--->转åç»ç¨äºç¼è¯è¿è¡è¯æµç¨æ·ç¨åºçæå¡å¨--->å°ç»æè¿åWebç½ç«æå¡å¨-->è¿åç»ç¨æ·éå¶å ç´ ï¼1ã硬件ï¼(1)èæ主æºæä¾ç»ç¨æ·ï¼ç½ç«å¶ä½è ï¼çæéæå°ï¼ä¸è½èªä¸»å®è£ æå¡å¨ç«¯è½¯ä»¶ï¼æ æ³æ建è¯æµå¹³å°ã(2)è¯æµæå¡å¨éè¦æå¾å¼ºçæ§è½ï¼å¦åæ æ³æ»¡è¶³å¤ç¨æ·åæ¶ç¼è¯è¿è¡è¯æµ(èæ主æºä¸å¯è½è¾¾å°)ãè´ä¹°ï¼ç§ç¨ï¼æå¡å¨è´¹ç¨æè´µ2ã软件ï¼å建ç«ç½ç«ç¸æ¯ï¼éè¦èªå·±é¢å¤ç¼åæå¡å¨é´åè°è½¯ä»¶åè¯æµç¨åºãå ¶ç¼ç¨è½ååç»éªè¦æ±å¾é«ã
写出下面题目的程序代码(C++) 并且输入输出都截个图 谢谢~
//记的以前学校时写过,好像是电商源码模板POJ的题目。源代码还在电脑上留着,bioendio源码仅供参考
#include <iostream>
#include <cmath>
using namespace std;
const int MAXN = ;
const int MAXM = ;
const int MAXP = ;
const int MAXT = 6;
struct Tpoint {
int x,HybridSource源码 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,源码token 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,猫猫源码 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);
}