Merge pull request #7 from KiritoTRw/master

QUST OJ Added.
This commit is contained in:
Kirigaya Kazuto 2016-04-28 09:00:15 +08:00
commit becd62f37a
6 changed files with 329 additions and 0 deletions

72
QUSTOJ/1017.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
//Kiritow's BIGN (class BigNumber) Written on Nov. 12th, 2015
//Original Version: Build 1 ( Version 2 )
class bign
{
public:
//WARNING: We use public here to reduce time consumed on Interface, although this is not a recommended way.
int data[20480];
void set_empty()
{
memset(data,0,sizeof(int)*20480);
}
int lenx()
{
for(int i=20480-1;i>=0;i--)
{
if(data[i]!=0) return i+1;
}
return 0;
}
};
bign a,b,ans;
char buff[10240];
int ConvertSTRtoBIGN_A(const char* incstr,bign& incbign)
{
int len=strlen(incstr);
for(int i=0;i<len;i++)
{
incbign.data[len-i-1]=incstr[i]-'0';
}
return len;
}
int main()
{
a.set_empty();
b.set_empty();
ans.set_empty();
gets(buff);
int lena=ConvertSTRtoBIGN_A(buff,a);
gets(buff);
int lenb=ConvertSTRtoBIGN_A(buff,b);
for(int i=0;i<lena;i++)
{
for(int j=0;j<lenb;j++)
{
ans.data[j+i]+=a.data[i]*b.data[j];
}
}
for(int i=0;i<20480;i++)
{
if(ans.data[i]>10)
{
ans.data[i+1]+=ans.data[i]/10;
ans.data[i]=ans.data[i]%10;
}
}
int slen=ans.lenx();
for(int i=0;i<slen;i++)
{
printf("%d",ans.data[slen-i-1]);
}
printf("\n");
return 0;
}

52
QUSTOJ/1101.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
//Written by Kiritow On Dec. 2ND, 2015
char map[500][500];
bool vis[500][500];
int xmax,ymax;
void dfs(int y,int x)
{
if(y<0||x<0||y>=ymax||x>=xmax) return;
if(vis[y][x]||map[y][x]=='*') return;
vis[y][x]=true;
dfs(y-1,x);
dfs(y+1,x);
dfs(y,x-1);
dfs(y,x+1);
}
int main()
{
scanf("%d %d",&xmax,&ymax);
for(int i=0;i<ymax;i++)
{
scanf("%s",&map[i][0]);
}
for(int i=0;i<xmax;i++)
{
if(map[0][i]!='*')
{
dfs(0,i);
break;
}
}
int cnt=0;
for(int i=0;i<ymax;i++)
{
for(int j=0;j<xmax;j++)
{
if(!vis[i][j]&&map[i][j]=='0')
{
cnt++;
}
}
}
printf("%d\n",cnt);
return 0;
}

32
QUSTOJ/1189.c Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
int main()
{
int plan[12];
int month,saved,now;
for(month=0,saved=0,now=0;month<12;month++)
{
scanf("%d",&plan[month]);
}
for(month=0;month<12;month++)
{
now+=300;
if(now-plan[month]>=100)
{
saved=saved+((now-plan[month])/100)*100;
now=now-((now-plan[month])/100)*100;
now=now-plan[month];
continue;
}
else if(now-plan[month]<0)
{
printf("%c%d\n",'-',month+1);
return 0;
}
else
{
now=now-plan[month];
}
}
printf("%d\n",now+(saved*6)/5);
return 0;
}

26
QUSTOJ/1226.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char cmdline[10240];
int main()
{
int line,word;
scanf("%d%*c",&line);
for(;line>0;line--)
{
memset(cmdline,0,10240);
gets(cmdline);
int i;
int len=strlen(cmdline);
word=0;
for(i=1;i<len-1;i++)
{
if(cmdline[i]==' '&&cmdline[i-1]!=' '&&cmdline[i+1]!=' ')
{
word++;
}
}
printf("%d\n",++word);
}
return 0;
}

118
QUSTOJ/1227.c Normal file
View File

@ -0,0 +1,118 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
char data;
int vis;
}pack;
pack screen[102][102];
#define RIGHT 0
#define DOWN 1
#define LEFT 2
#define UP 3
void deal(int incmax)
{
memset(screen,0,sizeof(pack)*102*102);
char letter='A';
int cx,cy,towards,i;
int times=incmax*incmax;
for(i=0;i<incmax+2;i++)
{
screen[0][i].vis=1;
screen[i][0].vis=1;
screen[incmax+1][i].vis=1;
screen[i][incmax+1].vis=1;
}
for(cx=1,cy=1,towards=RIGHT;times>0;times--)
{
screen[cx][cy].data=letter++;
screen[cx][cy].vis=1;
(letter>'Z')?(letter='A'):(NULL);
switch(towards)
{
case RIGHT:
{
if(screen[cx][cy+1].vis==1)
{
towards++;
cx++;
}
else
{
cy++;
}
break;
}
case DOWN:
{
if(screen[cx+1][cy].vis==1)
{
towards++;
cy--;
}
else
{
cx++;
}
break;
}
case LEFT:
{
if(screen[cx][cy-1].vis==1)
{
towards++;
cx--;
}
else
{
cy--;
}
break;
}
case UP:
{
if(screen[cx-1][cy].vis==1)
{
towards=0;
cy++;
}
else
{
cx--;
}
break;
}
}
}
}
void print_map(int incmax)
{
int x,y;
for(x=1;x<incmax+1;x++)
{
for(y=1;y<incmax;y++)
{
printf("%c ",screen[x][y].data);
}
printf("%c\n",screen[x][y].data);
}
}
int main()
{
int all,inc;
scanf("%d",&all);
for(;all>0;all--)
{
scanf("%d",&inc);
deal(inc);
print_map(inc);
}
return 0;
}

29
QUSTOJ/1228.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
int main()
{
int all,maxl,maxh;
int square,box;
int l,h;
scanf("%d",&all);
for(;all>0;all--)
{
square=0;box=0;
scanf("%d %d",&maxl,&maxh);
for(l=1;l<=maxl;l++)
{
for(h=1;h<=maxh;h++)
{
if(l==h)
{
square+=(maxl-l+1)*(maxh-h+1);
}
else
{
box+=(maxl-l+1)*(maxh-h+1);
}
}
}
printf("%d %d\n",square,box);
}
return 0;
}