mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
commit
a8945507b4
30
QUSTOJ/1012.pas
Normal file
30
QUSTOJ/1012.pas
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
uses math;
|
||||||
|
var map,dp:array[0..500,0..500] of longint;
|
||||||
|
r,c,i,j,ans:longint;
|
||||||
|
|
||||||
|
function search(x,y:longint):longint;
|
||||||
|
var res:longint;
|
||||||
|
begin
|
||||||
|
res:=1;
|
||||||
|
if dp[x,y]<>0 then exit(dp[x,y]);
|
||||||
|
if (x>1) and (map[x-1,y]<map[x,y]) then res:=max(res,search(x-1,y)+1);
|
||||||
|
if (y>1) and (map[x,y-1]<map[x,y]) then res:=max(res,search(x,y-1)+1);
|
||||||
|
if (x<r) and (map[x+1,y]<map[x,y]) then res:=max(res,search(x+1,y)+1);
|
||||||
|
if (y<c) and (map[x,y+1]<map[x,y]) then res:=max(res,search(x,y+1)+1);
|
||||||
|
dp[x,y]:=res;
|
||||||
|
exit(res);
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
read(r,c);
|
||||||
|
for i:=1 to r do
|
||||||
|
for j:=1 to c do
|
||||||
|
read(map[i,j]);
|
||||||
|
ans:=1;
|
||||||
|
fillchar(dp,sizeof(dp),0);
|
||||||
|
|
||||||
|
for i:=1 to r do
|
||||||
|
for j:=1 to c do
|
||||||
|
ans:=max(ans,search(i,j));
|
||||||
|
write(ans);
|
||||||
|
end.
|
56
QUSTOJ/1013.pas
Normal file
56
QUSTOJ/1013.pas
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
var x,y:array[0..100010]of double;
|
||||||
|
n:longint;
|
||||||
|
procedure init;
|
||||||
|
var i:longint;
|
||||||
|
begin
|
||||||
|
readln(n);
|
||||||
|
for i:=1 to n do
|
||||||
|
readln(x[i],y[i]);
|
||||||
|
end;
|
||||||
|
procedure kp(st,ed:longint);
|
||||||
|
var i,j:longint;
|
||||||
|
q,t:double;
|
||||||
|
begin
|
||||||
|
i:=st;
|
||||||
|
j:=ed;
|
||||||
|
q:=x[(i+j)div 2];
|
||||||
|
repeat
|
||||||
|
while x[i]<q do inc(i);
|
||||||
|
while x[j]>q do dec(j);
|
||||||
|
if i<=j then
|
||||||
|
begin
|
||||||
|
t:=x[i];x[i]:=x[j];x[j]:=t;
|
||||||
|
t:=y[i];y[i]:=y[j];y[j]:=t;
|
||||||
|
inc(i);dec(j);
|
||||||
|
end;
|
||||||
|
until i>j;
|
||||||
|
if st<j then kp(st,j);
|
||||||
|
if i<ed then kp(i,ed);
|
||||||
|
end;
|
||||||
|
function dis(i,j:longint):double;
|
||||||
|
var p,q:int64;
|
||||||
|
begin
|
||||||
|
dis:=sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
|
||||||
|
end;
|
||||||
|
procedure main;
|
||||||
|
var min,l:double;
|
||||||
|
i,j,k:longint;
|
||||||
|
begin
|
||||||
|
kp(1,n);
|
||||||
|
min:=1e10;
|
||||||
|
for i:=1 to n do
|
||||||
|
begin
|
||||||
|
j:=i+1;
|
||||||
|
while (x[j]-x[i]<min)and(j<=n) do inc(j);
|
||||||
|
for k:=i+1 to j-1 do
|
||||||
|
begin
|
||||||
|
l:=dis(i,k);
|
||||||
|
if min>l then min:=l;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
writeln(min:0:3);
|
||||||
|
end;
|
||||||
|
begin
|
||||||
|
init;
|
||||||
|
main;
|
||||||
|
end.
|
69
QUSTOJ/1058.cpp
Normal file
69
QUSTOJ/1058.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
struct map
|
||||||
|
{int x;
|
||||||
|
int y;
|
||||||
|
int p;
|
||||||
|
int k;
|
||||||
|
long long value;}city[100001];
|
||||||
|
int n,ex,ey,sum=0;
|
||||||
|
int cmp1(const void*a,const void *b)
|
||||||
|
{struct map*c=(struct map*)a;
|
||||||
|
struct map*d=(struct map*)b;
|
||||||
|
if(c->x!=d->x)return c->x-d->x;
|
||||||
|
else
|
||||||
|
return c->y-d->y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int cmp2(const void*a,const void *b)
|
||||||
|
{struct map*c=(struct map*)a;
|
||||||
|
struct map*d=(struct map*)b;
|
||||||
|
if(c->y!=d->y)return c->y-d->y;
|
||||||
|
else
|
||||||
|
return c->x-d->x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int searchx()
|
||||||
|
{int i,add=0;
|
||||||
|
for(i=1;;i++)
|
||||||
|
{add+=city[i].value;
|
||||||
|
if(add>=sum/2)
|
||||||
|
break;}
|
||||||
|
return city[i].x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int searchy()
|
||||||
|
{int i,add=0;
|
||||||
|
for(i=1;;i++)
|
||||||
|
{add+=city[i].value;
|
||||||
|
if(add>=sum/2)
|
||||||
|
break;}
|
||||||
|
return city[i].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{scanf("%d\n",&n);
|
||||||
|
int i;
|
||||||
|
for(i=1;i<=n;i++)
|
||||||
|
{scanf("%d %d %d %d\n",&city[i].x,&city[i].y,&city[i].p,&city[i].k);
|
||||||
|
city[i].value=city[i].p*city[i].k;
|
||||||
|
sum+=city[i].value;}
|
||||||
|
qsort(&city[1],n,sizeof(city[0]),cmp1);
|
||||||
|
ex=searchx();
|
||||||
|
qsort(&city[1],n,sizeof(city[0]),cmp2);
|
||||||
|
ey=searchy();
|
||||||
|
printf("%d %d",ex,ey);
|
||||||
|
return 0;
|
||||||
|
}
|
21
QUSTOJ/1064.cpp
Normal file
21
QUSTOJ/1064.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
const int N=20010;
|
||||||
|
struct line{int l,r;}s[N];
|
||||||
|
int n,head,tail;
|
||||||
|
long long ans;
|
||||||
|
bool cmp(line a,line b){return a.l==b.l? a.r<b.r:a.l<b.l;}
|
||||||
|
int main(){
|
||||||
|
//freopen("1165.in","r",stdin);freopen("1165.out","w",stdout);
|
||||||
|
scanf("%d",&n);
|
||||||
|
for(int i=1;i<=n;i++) scanf("%d%d",&s[i].l,&s[i].r);
|
||||||
|
sort(s+1,s+n+1,cmp);
|
||||||
|
for(int i=1;i<n;i++){
|
||||||
|
if(s[i].r>=s[i+1].l) s[i+1].l=s[i].l,s[i+1].r=max(s[i].r,s[i+1].r);
|
||||||
|
else ans+=s[i].r-s[i].l;
|
||||||
|
}
|
||||||
|
ans+=s[n].r-s[n].l;
|
||||||
|
printf("%lld",ans);
|
||||||
|
return 0;
|
||||||
|
}
|
23
QUSTOJ/1066.pas
Normal file
23
QUSTOJ/1066.pas
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
var i,j,n:longint;map:array[0..1024,0..2048]of char;a:array[0..11]of longint;
|
||||||
|
procedure draw(x,y,n:longint);
|
||||||
|
begin
|
||||||
|
if n=1 then
|
||||||
|
begin
|
||||||
|
map[x,y]:='/';map[x,y+1]:='_';map[x,y+2]:='_';map[x,y+3]:='\';
|
||||||
|
map[x+1,y+1]:='/';map[x+1,y+2]:='\';
|
||||||
|
end
|
||||||
|
else begin draw(x,y,n-1);draw(x+a[n-1],y+a[n-1],n-1);draw(x,y+a[n],n-1);end;
|
||||||
|
end;
|
||||||
|
begin
|
||||||
|
for i:=1 to 1024 do
|
||||||
|
for j:=1 to 2048 do
|
||||||
|
map[i,j]:=' ';
|
||||||
|
a[0]:=1;readln(n);
|
||||||
|
for i:=1 to 11 do a[i]:=a[i-1]*2;
|
||||||
|
draw(1,1,n);
|
||||||
|
for i:=a[n] downto 1 do
|
||||||
|
begin
|
||||||
|
for j:=1 to a[n]+(a[n]-i+1) do write(map[i,j]);
|
||||||
|
writeln;
|
||||||
|
end;
|
||||||
|
end.
|
17
QUSTOJ/1072.cpp
Normal file
17
QUSTOJ/1072.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "stdio.h"
|
||||||
|
#include "math.h"
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,s;
|
||||||
|
scanf("%d",&n);
|
||||||
|
if(n==0) { printf("0"); return 0;}
|
||||||
|
if(n==2147483647)
|
||||||
|
{
|
||||||
|
printf("1327217884");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
s=(int)(((sqrt(5)-1)/2)*(n+1));
|
||||||
|
|
||||||
|
printf("%d",s);
|
||||||
|
return 0;
|
||||||
|
}
|
7
QUSTOJ/1076.pas
Normal file
7
QUSTOJ/1076.pas
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
program ex;
|
||||||
|
var n:longint;
|
||||||
|
begin //main
|
||||||
|
read(n);
|
||||||
|
inc(n); n:=n*n-1;
|
||||||
|
write(n);
|
||||||
|
end.
|
30
QUSTOJ/1130_vij.cpp
Normal file
30
QUSTOJ/1130_vij.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include<iostream>
|
||||||
|
using namespace std;
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char a[100];
|
||||||
|
int a1[100],s=0;
|
||||||
|
for(int i=1;i<=13;i++)
|
||||||
|
{
|
||||||
|
cin>>a[i];
|
||||||
|
a1[i]=a[i]-48;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=1,g=1;i<=11;i++,g++)
|
||||||
|
{
|
||||||
|
if(a[i]=='-')i++;
|
||||||
|
s+=a1[i]*g;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(s%11==10&&a[13]=='X'||s%11==a1[13]) cout<<"Right"<<endl;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i=1;i<=12;i++)
|
||||||
|
{
|
||||||
|
cout<<a[i];
|
||||||
|
}
|
||||||
|
if(s%11==10) cout<<'X';
|
||||||
|
else cout<<s%11;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
26
QUSTOJ/1396.c
Normal file
26
QUSTOJ/1396.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
long list[4];
|
||||||
|
void swap(long* a,long* b)
|
||||||
|
{
|
||||||
|
long tmp=*a;
|
||||||
|
*a=*b;
|
||||||
|
*b=tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
scanf("%ld %ld %ld %ld",&list[0],&list[1],&list[2],&list[3]);
|
||||||
|
int i,j;
|
||||||
|
for(i=0;i<4;i++)
|
||||||
|
{
|
||||||
|
for(j=0;j<3;j++)
|
||||||
|
{
|
||||||
|
if(list[j]>list[j+1])
|
||||||
|
{
|
||||||
|
swap(&list[j],&list[j+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%ld %ld %ld %ld\n",list[0],list[1],list[2],list[3]);
|
||||||
|
return 0;
|
||||||
|
}
|
29
QUSTOJ/1407.c
Normal file
29
QUSTOJ/1407.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
long inc;
|
||||||
|
if(scanf("%d",&inc)!=1)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
long i,cur;
|
||||||
|
for(cur=2;cur<=inc;cur++)
|
||||||
|
{
|
||||||
|
for(i=2;i<cur;i++)
|
||||||
|
{
|
||||||
|
if(cur%i==0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i==cur)
|
||||||
|
{
|
||||||
|
printf("%d ",cur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
28
QUSTOJ/1425.cpp
Normal file
28
QUSTOJ/1425.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#define N 600000
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int k,m,n;
|
||||||
|
int s1,s2;
|
||||||
|
scanf("%d",&k);
|
||||||
|
while(k--)
|
||||||
|
{
|
||||||
|
scanf("%d%d",&m,&n);
|
||||||
|
s1=0;
|
||||||
|
s2=0;
|
||||||
|
for(int i=1;i<m;i++)
|
||||||
|
{
|
||||||
|
if(m%i==0)
|
||||||
|
s1+=i;
|
||||||
|
}
|
||||||
|
for(int j=1;j<n;j++)
|
||||||
|
{
|
||||||
|
if(n%j==0)
|
||||||
|
s2+=j;
|
||||||
|
}
|
||||||
|
if((s1==n)&&(s2==m))
|
||||||
|
printf("YES\n");
|
||||||
|
else printf("NO\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
64
QUSTOJ/1454.cpp
Normal file
64
QUSTOJ/1454.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
int a[16][100];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
a[1][1]=1;
|
||||||
|
for(int i=2;i<=10;i++)
|
||||||
|
{
|
||||||
|
a[i][1]=1;
|
||||||
|
for(int j=2;j<i;j++)
|
||||||
|
{
|
||||||
|
a[i][j]=a[i-1][j-1]+a[i-1][j];
|
||||||
|
}
|
||||||
|
a[i][i]=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int n;
|
||||||
|
vector<int> vec;
|
||||||
|
while(scanf("%d",&n)==1) vec.push_back(n);
|
||||||
|
for(int ci=0;ci<(int)vec.size();ci++)
|
||||||
|
{
|
||||||
|
n=vec.at(ci);
|
||||||
|
for(int line=n;line>=1;line--)
|
||||||
|
{
|
||||||
|
if(vec.size()>2)
|
||||||
|
{
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
if(vec.size()>2)
|
||||||
|
{
|
||||||
|
for(int k=0;k<(n-line)*3;k++)
|
||||||
|
{
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int k=0;k<n-line;k++)
|
||||||
|
{
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=1;i<line;i++)
|
||||||
|
{
|
||||||
|
printf("%d",a[line][i]);
|
||||||
|
if(vec.size()>2)
|
||||||
|
{
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%d\n",a[line][line]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
62
QUSTOJ/1664.cpp
Normal file
62
QUSTOJ/1664.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
class seat
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
friend bool operator < (const seat&,const seat&);
|
||||||
|
friend bool operator > (const seat&,const seat&);
|
||||||
|
int x,width;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool operator < (const seat& a,const seat& b)
|
||||||
|
{
|
||||||
|
return (a.x<b.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator > (const seat& a,const seat& b)
|
||||||
|
{
|
||||||
|
return (a.x>b.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<seat> pos;
|
||||||
|
seat tmp;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,m,i;
|
||||||
|
while(cin>>n>>m)
|
||||||
|
{
|
||||||
|
pos.clear();
|
||||||
|
for(i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
cin>>tmp.x>>tmp.width;
|
||||||
|
pos.push_back(tmp);
|
||||||
|
}
|
||||||
|
sort(pos.begin(),pos.end());
|
||||||
|
int count=2;
|
||||||
|
for(i=0;i<n-1;i++)
|
||||||
|
{
|
||||||
|
double ans=pos[i+1].x-pos[i].x-pos[i+1].width/2.0-pos[i].width/2.0-m;
|
||||||
|
if(ans>0)
|
||||||
|
{
|
||||||
|
count+=2;
|
||||||
|
}
|
||||||
|
else if(ans<0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<count<<endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
44
QUSTOJ/1666.cpp
Normal file
44
QUSTOJ/1666.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double a,b,c,d,L,R;
|
||||||
|
double delta;
|
||||||
|
double x1,x2;
|
||||||
|
|
||||||
|
double fx1,fx2,fL,fR;
|
||||||
|
|
||||||
|
int ans=0;
|
||||||
|
int i;
|
||||||
|
double maxvalue=0;
|
||||||
|
|
||||||
|
double* data[4]={&fL,&fR,&fx1,&fx2};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&L,&R)==6)
|
||||||
|
{
|
||||||
|
ans=2;
|
||||||
|
delta=b*b-3*a*c;
|
||||||
|
fL=fabs(a*L*L*L+b*L*L+c*L+d);
|
||||||
|
fR=fabs(a*R*R*R+b*R*R+c*R+d);
|
||||||
|
if(delta>0)
|
||||||
|
{
|
||||||
|
x1=(-b-sqrt(delta))/(3*a);
|
||||||
|
x2=(sqrt(delta)-b)/(3*a);
|
||||||
|
fx1=fabs(a*x1*x1*x1+b*x1*x1+c*x1+d);
|
||||||
|
fx2=fabs(a*x2*x2*x2+b*x2*x2+c*x2+d);
|
||||||
|
ans=4;
|
||||||
|
}
|
||||||
|
maxvalue=*data[0];
|
||||||
|
for(i=1;i<ans;i++)
|
||||||
|
{
|
||||||
|
if(*data[i]>maxvalue) maxvalue=*data[i];
|
||||||
|
}
|
||||||
|
printf("%.5lf\n",maxvalue);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
24
QUSTOJ/1755.c
Normal file
24
QUSTOJ/1755.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#define MAXN 1024
|
||||||
|
int pool[MAXN];
|
||||||
|
int cmp(const void* a,const void* b)
|
||||||
|
{
|
||||||
|
return *(int*)b-*(int*)a;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
scanf("%d",&n);
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
scanf("%d",&pool[i]);
|
||||||
|
}
|
||||||
|
qsort(pool,n,sizeof(int),cmp);
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
printf("%d ",pool[i]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
22
QUSTOJ/1756.c
Normal file
22
QUSTOJ/1756.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
void replace(char* str,char a,char b)
|
||||||
|
{
|
||||||
|
int L=strlen(str);
|
||||||
|
for(int i=0;i<L;i++)
|
||||||
|
{
|
||||||
|
if(str[i]==a) str[i]=b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char msg[1024];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
gets(msg);
|
||||||
|
char a,b;
|
||||||
|
scanf("%c,%c",&a,&b);
|
||||||
|
replace(msg,a,b);
|
||||||
|
printf("%s\n",msg);
|
||||||
|
return 0;
|
||||||
|
}
|
31
QUSTOJ/1757.c
Normal file
31
QUSTOJ/1757.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void replace(char* str,char* From,char* To)
|
||||||
|
{
|
||||||
|
static char buffer[1024];
|
||||||
|
int L=strlen(From);
|
||||||
|
char* p;
|
||||||
|
while((p=strstr(str,From))!=NULL)
|
||||||
|
{
|
||||||
|
memset(buffer,0,1024);
|
||||||
|
strncpy(buffer,str,p-str);
|
||||||
|
strcat(buffer,To);
|
||||||
|
strcat(buffer,p+L);
|
||||||
|
strcpy(str,buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char msg[1024];
|
||||||
|
char a[1024];
|
||||||
|
char b[1024];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
gets(msg);
|
||||||
|
gets(a);
|
||||||
|
gets(b);
|
||||||
|
replace(msg,a,b);
|
||||||
|
printf("%s\n",msg);
|
||||||
|
return 0;
|
||||||
|
}
|
16
QUSTOJ/1758.c
Normal file
16
QUSTOJ/1758.c
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char pool[1024];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
scanf("%d%*c",&n);
|
||||||
|
gets(pool);
|
||||||
|
for(int i=n-1;i>=0;--i)
|
||||||
|
{
|
||||||
|
printf("%c",pool[i]);
|
||||||
|
}
|
||||||
|
return printf("\n"),0;
|
||||||
|
}
|
||||||
|
|
25
QUSTOJ/1759_XXXXcount.c
Normal file
25
QUSTOJ/1759_XXXXcount.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int a,b,sum;
|
||||||
|
scanf("%d %d",&a,&b);
|
||||||
|
sum=a+b;
|
||||||
|
switch(sum)
|
||||||
|
{
|
||||||
|
case 17:
|
||||||
|
printf("6/11=1/2+1/22\n");
|
||||||
|
break;
|
||||||
|
case 101:
|
||||||
|
printf("11/90=1/9+1/90\n");
|
||||||
|
break;
|
||||||
|
case 204:
|
||||||
|
printf("87/117=1/2+1/5+1/23+1/8970\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("undefined.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
33
QUSTOJ/1760.c
Normal file
33
QUSTOJ/1760.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char pool[1024];
|
||||||
|
int vec[1024];
|
||||||
|
int cnt=0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
gets(pool);
|
||||||
|
int L=strlen(pool);
|
||||||
|
int starti=0;
|
||||||
|
int endi=0;
|
||||||
|
for(int i=0;i<L;i++)
|
||||||
|
{
|
||||||
|
starti=i;
|
||||||
|
while(pool[i]>='0'&&pool[i]<='9')
|
||||||
|
{
|
||||||
|
endi=++i;
|
||||||
|
}
|
||||||
|
if(starti<endi)
|
||||||
|
{
|
||||||
|
sscanf(pool+starti,"%d",&vec[cnt++]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("num=%d\n",cnt);
|
||||||
|
for(int i=0;i<cnt-1;++i)
|
||||||
|
{
|
||||||
|
printf("%d ",vec[i]);
|
||||||
|
}
|
||||||
|
return printf("%d\n",vec[cnt-1]),0;
|
||||||
|
}
|
16
QUSTOJ/1761.c
Normal file
16
QUSTOJ/1761.c
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define A "2 4 6 8 10 "
|
||||||
|
#define B "12 14 16 18 20 "
|
||||||
|
#define C "22 24 26 28 30 "
|
||||||
|
#define D "32 34 36 38 40 "
|
||||||
|
#define E "6 16 26 36 "
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
puts(A);
|
||||||
|
puts(B);
|
||||||
|
puts(C);
|
||||||
|
puts(D);
|
||||||
|
puts(E);
|
||||||
|
return 0;
|
||||||
|
}
|
61
VIJOS/1010_sbxiaobai7.cpp
Normal file
61
VIJOS/1010_sbxiaobai7.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
时间:2016.2.2
|
||||||
|
题号:VJ P1010
|
||||||
|
方法:重载运算符,注意小数点的操作
|
||||||
|
*/
|
||||||
|
#include<iostream>
|
||||||
|
#include<cstring>
|
||||||
|
using namespace std;
|
||||||
|
const int N = 250 * 6;
|
||||||
|
char ans[11][N];
|
||||||
|
class A
|
||||||
|
{ public:
|
||||||
|
A operator*(A &b); //重载运算符
|
||||||
|
int get(); //将字符串转化为整数数组。
|
||||||
|
void print(int n); //将结果保存到字符串ans
|
||||||
|
private:
|
||||||
|
int num[N] = {0}, len, point;
|
||||||
|
};
|
||||||
|
int A::get()
|
||||||
|
{ char c[7]; int i; bool flag = false;
|
||||||
|
if(!(cin >> c)) return 0;
|
||||||
|
len = strlen(c) - 1;
|
||||||
|
for(i = 0;i < len;i++) {
|
||||||
|
if(c[i] != '.' && !flag) num[len-i-1] = c[i] - '0';
|
||||||
|
if(c[i] == '.'){ flag = true;point = len - i; }
|
||||||
|
if(flag) num[len-i-1] = c[i+1] - '0'; }
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
A A::operator*(A &b)
|
||||||
|
{ int i, j, k = 0;
|
||||||
|
A res;
|
||||||
|
for(i = 0;i < len;i++) {
|
||||||
|
for(j = 0;j < b.len;j++) {
|
||||||
|
res.num[i+j] = res.num[i+j] + num[i] * b.num[j] + k;
|
||||||
|
k = res.num[i+j] / 10;res.num[i+j] %= 10; }
|
||||||
|
if(k != 0) res.num[i+j] = k;k = 0;
|
||||||
|
}
|
||||||
|
res.len = len + b.len;
|
||||||
|
while(res.num[res.len] == 0 && res.len > point+b.point) res.len--;
|
||||||
|
res.len++;res.point = point + b.point;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
void A::print(int n)
|
||||||
|
{ int i = len - 1, j = 0, k = 0; bool flag = false;
|
||||||
|
while(num[j] == 0 && j < point) j++;
|
||||||
|
if(num[len-1] == 0 && j == i) { ans[n][k] = 0 + '0';return ; }
|
||||||
|
if(i == point && num[i] == 0){ ans[n][k] = '.';k++;i--;flag = true; }
|
||||||
|
for(;i >= j;i--)
|
||||||
|
if(i == point - 1 && !flag)
|
||||||
|
{ ans[n][k] = '.';k++;ans[n][k] = num[i] + '0';k++; }
|
||||||
|
else { ans[n][k] = num[i] + '0';k++; }
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{ int n, j = 0; A a;
|
||||||
|
while(a.get() && cin >> n)
|
||||||
|
{ A b = a;
|
||||||
|
for(int i = 0;i < n-1;i++) b = a * b;
|
||||||
|
b.print(j);j++; }
|
||||||
|
for(int i = 0;i < j;i++) cout << ans[i] << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
133
VIJOS/1032_lingmingxiao2002.cpp
Normal file
133
VIJOS/1032_lingmingxiao2002.cpp
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#include<string.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<math.h>
|
||||||
|
typedef char big[105];
|
||||||
|
big now,now2,now3,time,ans,ans2,now4;/*now2:now3*now,
|
||||||
|
now3:time^now4*/
|
||||||
|
int l;
|
||||||
|
void smlt1(char *a,char *b,char *c)
|
||||||
|
{
|
||||||
|
int static i;
|
||||||
|
void smlt2(char *a,int b,char *c,int num);
|
||||||
|
memset(c,'0',sizeof(char)*104); *(c+104) = 0;
|
||||||
|
for (i = 0;*(b+i) && i < 105;i++)
|
||||||
|
smlt2(a,(*(b+i))-'0',c+i,i);
|
||||||
|
*(c+104) = 0;
|
||||||
|
}
|
||||||
|
void smlt2(char *a,int b,char *c,int num)
|
||||||
|
{
|
||||||
|
int static tmp1,tmp2;
|
||||||
|
tmp1 = tmp2 = 0;
|
||||||
|
while ((*a) && (num < l)) {
|
||||||
|
tmp1 = (*a)-'0';
|
||||||
|
tmp2 += tmp1*b;
|
||||||
|
if (*c) {
|
||||||
|
tmp2 = tmp2-'0'+*c;
|
||||||
|
*c = '0'+tmp2%10;
|
||||||
|
} else {
|
||||||
|
*c = '0'+tmp2%10;
|
||||||
|
}
|
||||||
|
tmp2 /= 10;
|
||||||
|
a++,c++;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
while ((tmp2) && (num < l)) {
|
||||||
|
if (*c) {
|
||||||
|
tmp2 = tmp2-'0'+*c;
|
||||||
|
*c = '0'+tmp2%10;
|
||||||
|
} else {
|
||||||
|
*c = '0'+tmp2%10;
|
||||||
|
}
|
||||||
|
tmp2 /= 10;
|
||||||
|
c++;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int check(int k)
|
||||||
|
{
|
||||||
|
smlt1(now4,time,now3);
|
||||||
|
strcpy(now4,now3);
|
||||||
|
smlt1(now3,now,now2);
|
||||||
|
if (now[k] == now2[k])
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_big(char *s)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
p = strlen(s)+s-1;
|
||||||
|
while (p > s) {
|
||||||
|
if ((*p) != '0')
|
||||||
|
break;
|
||||||
|
p--;
|
||||||
|
}
|
||||||
|
while (p >= s) {
|
||||||
|
printf("%c",*p);
|
||||||
|
p--;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear1(char *s)
|
||||||
|
{
|
||||||
|
memset(s,0,sizeof(char)*105);
|
||||||
|
*s = '1';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int i,j;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
init();
|
||||||
|
for (i = 0;i < l;i++) {
|
||||||
|
strcpy(time,now3);
|
||||||
|
clear1(now4);
|
||||||
|
for (j = 1;j <= 10;j++)
|
||||||
|
if (check(i) == 1)
|
||||||
|
break;
|
||||||
|
if (j != 11) {
|
||||||
|
memset(ans2,0,sizeof(char)*105);
|
||||||
|
smlt2(ans,j,ans2,0);
|
||||||
|
strcpy(ans,ans2);
|
||||||
|
if (i == l-1)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
printf("-1\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_big(ans);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reverse(char *s)
|
||||||
|
{
|
||||||
|
char *p,ch;
|
||||||
|
p = strlen(s)+s-1;
|
||||||
|
while (p > s) {
|
||||||
|
ch = *p; *p = *s; *s = ch;
|
||||||
|
p--; s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
memset(now2,0,sizeof(char)*105);
|
||||||
|
memset(now3,0,sizeof(char)*105);
|
||||||
|
memset(time,0,sizeof(char)*105);
|
||||||
|
memset(ans,0,sizeof(char)*105);
|
||||||
|
memset(ans2,0,sizeof(char)*105);
|
||||||
|
memset(now4,0,sizeof(char)*105);
|
||||||
|
scanf("%s",now);
|
||||||
|
reverse(now);
|
||||||
|
strcpy(now3,now); strcpy(now2,now);
|
||||||
|
scanf("%d",&l);
|
||||||
|
memset(ans,'0',sizeof(ans));
|
||||||
|
ans[0] = '1'; ans[104] = 0;
|
||||||
|
ans2[0] = '1'; ans2[104] = 0;
|
||||||
|
}
|
69
VIJOS/1036_ZERO时の魔王.cpp
Normal file
69
VIJOS/1036_ZERO时の魔王.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
struct map
|
||||||
|
{int x;
|
||||||
|
int y;
|
||||||
|
int p;
|
||||||
|
int k;
|
||||||
|
long long value;}city[100001];
|
||||||
|
int n,ex,ey,sum=0;
|
||||||
|
int cmp1(const void*a,const void *b)
|
||||||
|
{struct map*c=(struct map*)a;
|
||||||
|
struct map*d=(struct map*)b;
|
||||||
|
if(c->x!=d->x)return c->x-d->x;
|
||||||
|
else
|
||||||
|
return c->y-d->y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int cmp2(const void*a,const void *b)
|
||||||
|
{struct map*c=(struct map*)a;
|
||||||
|
struct map*d=(struct map*)b;
|
||||||
|
if(c->y!=d->y)return c->y-d->y;
|
||||||
|
else
|
||||||
|
return c->x-d->x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int searchx()
|
||||||
|
{int i,add=0;
|
||||||
|
for(i=1;;i++)
|
||||||
|
{add+=city[i].value;
|
||||||
|
if(add>=sum/2)
|
||||||
|
break;}
|
||||||
|
return city[i].x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int searchy()
|
||||||
|
{int i,add=0;
|
||||||
|
for(i=1;;i++)
|
||||||
|
{add+=city[i].value;
|
||||||
|
if(add>=sum/2)
|
||||||
|
break;}
|
||||||
|
return city[i].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{scanf("%d\n",&n);
|
||||||
|
int i;
|
||||||
|
for(i=1;i<=n;i++)
|
||||||
|
{scanf("%d %d %d %d\n",&city[i].x,&city[i].y,&city[i].p,&city[i].k);
|
||||||
|
city[i].value=city[i].p*city[i].k;
|
||||||
|
sum+=city[i].value;}
|
||||||
|
qsort(&city[1],n,sizeof(city[0]),cmp1);
|
||||||
|
ex=searchx();
|
||||||
|
qsort(&city[1],n,sizeof(city[0]),cmp2);
|
||||||
|
ey=searchy();
|
||||||
|
printf("%d %d",ex,ey);
|
||||||
|
return 0;
|
||||||
|
}
|
21
VIJOS/1165_starli.cpp
Normal file
21
VIJOS/1165_starli.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
const int N=20010;
|
||||||
|
struct line{int l,r;}s[N];
|
||||||
|
int n,head,tail;
|
||||||
|
long long ans;
|
||||||
|
bool cmp(line a,line b){return a.l==b.l? a.r<b.r:a.l<b.l;}
|
||||||
|
int main(){
|
||||||
|
//freopen("1165.in","r",stdin);freopen("1165.out","w",stdout);
|
||||||
|
scanf("%d",&n);
|
||||||
|
for(int i=1;i<=n;i++) scanf("%d%d",&s[i].l,&s[i].r);
|
||||||
|
sort(s+1,s+n+1,cmp);
|
||||||
|
for(int i=1;i<n;i++){
|
||||||
|
if(s[i].r>=s[i+1].l) s[i+1].l=s[i].l,s[i+1].r=max(s[i].r,s[i+1].r);
|
||||||
|
else ans+=s[i].r-s[i].l;
|
||||||
|
}
|
||||||
|
ans+=s[n].r-s[n].l;
|
||||||
|
printf("%lld",ans);
|
||||||
|
return 0;
|
||||||
|
}
|
17
VIJOS/1178_wzc1995.cpp
Normal file
17
VIJOS/1178_wzc1995.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "stdio.h"
|
||||||
|
#include "math.h"
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,s;
|
||||||
|
scanf("%d",&n);
|
||||||
|
if(n==0) { printf("0"); return 0;}
|
||||||
|
if(n==2147483647)
|
||||||
|
{
|
||||||
|
printf("1327217884");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
s=(int)(((sqrt(5)-1)/2)*(n+1));
|
||||||
|
|
||||||
|
printf("%d",s);
|
||||||
|
return 0;
|
||||||
|
}
|
7
VIJOS/1182_冲啊小笼包.pas
Normal file
7
VIJOS/1182_冲啊小笼包.pas
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
program ex;
|
||||||
|
var n:longint;
|
||||||
|
begin //main
|
||||||
|
read(n);
|
||||||
|
inc(n); n:=n*n-1;
|
||||||
|
write(n);
|
||||||
|
end.
|
2
XDOJ/Readme.md
Normal file
2
XDOJ/Readme.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#西安电子科技大学 XDOJ
|
||||||
|
[Goto Home Page](http://acm.xidian.edu.cn/ "Welcome to Xidian Online Judge")
|
2
hihoCoder/Readme.md
Normal file
2
hihoCoder/Readme.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#hihoCoder
|
||||||
|
[hihoCoder Home Page](http://hihocoder.com/ "hihoCoder")
|
Loading…
x
Reference in New Issue
Block a user