Merge pull request #6 from Kiritow/master

Catch up with you~
This commit is contained in:
KiritoTRw 2016-05-02 14:06:03 +08:00
commit 3702613ed8
6 changed files with 211 additions and 0 deletions

104
QUSTOJ/1041_csdn.cpp Normal file
View File

@ -0,0 +1,104 @@
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int maxn = (1 << 17), oo = 1000000000, nil = 0;
int N, M, tim[105], reqt[105], reqf[105], rest[105], resf[105];
int e, pnt[maxn], nxt[maxn << 2], u[maxn << 2], v[maxn << 2], w[maxn << 2];
int d[maxn];
bool vis[maxn];
struct node
{
int n, dis;
node(int n = 0, int dis = 0) :n(n), dis(dis) {}
bool operator < (const node& b) const
{
return dis > b.dis;
}
};
void addedge(int a, int b, int c)
{
u[++e] = a; v[e] = b; w[e] = c;
nxt[e] = pnt[a]; pnt[a] = e;
}
void init()
{
char ch[25];
scanf("%d%d", &N, &M);
for(int i = 1; i <= M; ++i)
{
scanf("%d", &tim[i]);
scanf("%s", &ch);
for(int j = 0; j < N; ++j)
{
if(ch[j] == '+')
{
reqt[i] |= (1 << j);
}
if(ch[j] == '-')
{
reqf[i] |= (1 << j);
}
}
scanf("%s", &ch);
for(int j = 0; j < N; ++j)
{
if(ch[j] == '+')
{
rest[i] |= (1 << j);
}
if(ch[j] == '-')
{
resf[i] |= (1 << j);
}
}
}
for(int i = (1 << N) - 1; i >= 0; --i)
{
for(int j = 1; j <= M; ++j)
{
if(((i & reqt[j]) == reqt[j]) && ((i & reqf[j]) == 0))
{
addedge(i, (i & (~resf[j]) | rest[j]), tim[j]);
}
}
}
}
void work()
{
int S = (1 << N) - 1, T = 0;
memset(d, 0x3f, sizeof(d));
memset(vis, 0, sizeof(vis));
priority_queue <node> Q;
d[S] = 0;
Q.push(node(S, 0));
while(!Q.empty())
{
node tmp = Q.top();
Q.pop();
vis[tmp.n] = true;
for(int j = pnt[tmp.n]; j != nil; j = nxt[j])
{
if((!vis[v[j]]) && d[v[j]] > tmp.dis + w[j])
{
d[v[j]] = tmp.dis + w[j];
Q.push(node(v[j], d[v[j]]));
}
}
}
if(d[T] > oo)
{
puts("0");
}
else
{
printf("%d\n", d[T]);
}
}
int main()
{
init();
work();
return 0;
}

20
QUSTOJ/1079.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
int main()
{
int n,x1,x2,x3,x4,i,j,k,m,s,v;
double time,min;
min=2000;
scanf("%d%d%d%d%d",&n,&x1,&x2,&x3,&x4);
for(i=0;i<=10;i++)
for(j=0;j<=10;j++)
for(k=0;k<=10;k++)
if((i+j+k)<=n)
{
m=n-i-j-k;
time=((20.0-i*2)*x1+((100.0-j*7)*x2*2+(100.0-k*9)*x3)/((10.0+m)*x4));
if(time<min) min=time;
time=0;
}
printf("%.3lf",min);
return 0;
}

13
QUSTOJ/1079.pas Normal file
View File

@ -0,0 +1,13 @@
var
k,ld,cbs,cd,md,i,x1,x2,x3,x4:integer;
sj:real;
begin
read(k,x1,x2,x3,x4);
sj:=99999999;
for ld:=0 to 10 do
for cbs:=0 to 10 do
for cd:=0 to 10 do
for md:=0 to 10 do
if (ld+cbs+cd+md=k) and (((20-ld*2)*x1+(100-cbs*7)*x2*2/((10+md*1)*x4)+(100-cd*9)*x3/((10+md*1)*x4))<sj) then sj:=(20-ld*2)*x1+(100-cbs*7)*x2*2/((10+md*1)*x4)+(100-cd*9)*x3/((10+md*1)*x4);
write(sj:0:3);
end.

37
QUSTOJ/1513.cpp Normal file
View File

@ -0,0 +1,37 @@
//Problem1513
#include <cstdio>
#include <cstring>
using namespace std;
char buff[256];
int main()
{
while(scanf("%s",buff)==1)
{
int len=strlen(buff);
for(int i=0;i<len;i++)
{
if(buff[i]>='A'&&buff[i]<='Z')
{
buff[i]=(buff[i]-'A'+1)%26+'a';
}
else if(buff[i]>='a'&&buff[i]<='z')
{
char ans;
switch(buff[i])
{
case 'a':case 'b':case 'c':ans='1';break;
case 'd':case 'e':case 'f':ans='2';break;
case 'g':case 'h':case 'i':ans='3';break;
case 'j':case 'k':case 'l':ans='4';break;
case 'm':case 'n':case 'o':ans='5';break;
case 'p':case 'q':case 'r':case 's':ans='6';break;
case 't':case 'u':case 'v':ans='7';break;
case 'w':case 'x':case 'y':case 'z':ans='8';break;
}
ans++;
buff[i]=ans;
}
}
printf("%s\n",buff);
}
}

20
VIJOS/1248.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
int main()
{
int n,x1,x2,x3,x4,i,j,k,m,s,v;
double time,min;
min=2000;
scanf("%d%d%d%d%d",&n,&x1,&x2,&x3,&x4);
for(i=0;i<=10;i++)
for(j=0;j<=10;j++)
for(k=0;k<=10;k++)
if((i+j+k)<=n)
{
m=n-i-j-k;
time=((20.0-i*2)*x1+((100.0-j*7)*x2*2+(100.0-k*9)*x3)/((10.0+m)*x4));
if(time<min) min=time;
time=0;
}
printf("%.3lf",min);
return 0;
}

17
VIJOS/1248.pas Normal file
View File

@ -0,0 +1,17 @@
var m,s:double;
k,x1,x2,x3,x4,i1,i2,i3,i4,v:longint;
begin
read(k,x1,x2,x3,x4);
m:=maxlongint;
for i1:=0 to 10 do
for i2:=0 to 10 do
for i3:=0 to 10 do
for i4:=0 to 10 do
if (i1+i2+i3+i4<=k) then
begin
v:=(10+i4)x4;
s:=(20-i12)x1+(100-i27)x22/v+(100-i39)x3/v;
if (s<m) and (v>0) then m:=s;
end;
write(m:0:3);
end.