The code should be like this:
if(timeleft <= 1)return one_point;
timeleft -= gettime(sx,sy);
one_point += getpoint(sx,sy);
If you have a lifetime 1, you cannot have the score, but if you have a lifetime larger than 2, even if you have a negative lifetime after bump, you will have the score.
114 - Simulation Wizardry
Moderator: Board moderators
-
- New poster
- Posts: 1
- Joined: Tue Jan 19, 2010 10:42 am
114 WA!! give me a more test data (or fix my code)
The sample input was correct. So I submitted in the online judge. But Wrong Answer!!!
help me TT.
give me more test data or fix my code please!!
help me TT.
give me more test data or fix my code please!!
Code: Select all
#include<iostream>
using namespace std;
int main()
{
int a[100][100], walld, wan, dlife[1000], x, y, wsc[1000], score, life, pos, i, j, m, n, tscore = 0;
cin >> m >> n >> walld >> wan;
fill(a[0], a[0]+m, -1);
fill(a[n-1], a[n-1]+m, -1);
for(i = 0; i < n; i++) {
a[i][0] = -1;
a[i][m-1] = -1;
}
for(i = 0; i < wan; i++) {
cin >> x >> y >> wsc[i] >> dlife[i];
a[x-1][y-1] = i;
}
while(1) {
cin >> x >> y >> pos >> life;
if(cin.eof()) {
cout << tscore << endl;
break;
}
score = 0;
x--;
y--;
for(i = 0; i < life; i++) {
if(pos == 0) {
if(a[x+1][y] == -1) {
i += walld;
pos++;
}
else if(a[x+1][y] >= 0) {
i += dlife[a[x+1][y]];
score += wsc[a[x+1][y]];
pos++;
}
else x++;
}
else if(pos == 1) {
if(a[x][y+1] == -1) {
i += walld;
pos++;
}
else if(a[x][y+1] >= 0) {
i += dlife[a[x][y+1]];
score += wsc[a[x][y+1]];
pos++;
}
else y++;
}
else if(pos == 2) {
if(a[x-1][y] == -1) {
i += walld;
pos++;
}
else if(a[x-1][y] >= 0) {
i += dlife[a[x-1][y]];
score += wsc[a[x-1][y]];
pos++;
}
else x--;
}
else if(pos == 3) {
if(a[x][y-1] == -1) {
i += walld;
pos = 0;
}
else if(a[x][y-1] >= 0) {
i += dlife[a[x][y-1]];
score += wsc[a[x][y-1]];
pos = 0;
}
else y--;
}
}
tscore += score;
cout << score << endl;
}
return 0;
}
Wrong Answer On 114 Can u help me?
I try this problem a lot but get wrong answer. May be I have some wrong concept with the problem or wrong code but I cann't fixed it. Can u please help me. Here is my code :
Code: Select all
#include<iostream>
using namespace std;
int main()
{
long co[51][51],bo[51][51],gr[51][51];
long x,y,p,m,n,c,d,b,l,t;
long i,j,f;
cin>>m>>n;
t=0;
cin>>c;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
co[i][j]=1;
bo[i][j]=0;
if(i==m||i==1||j==n||j==1)
{
gr[i][j]=1;
co[i][j]+=c;
}
else
gr[i][j]=0;
}
}
cin>>p;
for(i=0;i<p;i++)
{
cin>>x>>y>>b>>c;
co[x][y]+=c;
bo[x][y]+=b;
gr[x][y]=1;
}
t=0;
while(!(cin>>x>>y>>d>>l).eof())
{
b=0;
while(l>0)
{
if(d==1)
{
if(gr[x][y+1]==1)
{
if(l>1)
b=b+bo[x][y+1];
l=l-co[x][y+1];
d=0;
}
else
{
y++;
l=l-co[x][y];
}
}
else if(d==0)
{
if(gr[x+1][y]==1)
{
if(l>1)
b=b+bo[x+1][y];
l=l-co[x+1][y];
d=3;
}
else
{
x++;
l=l-co[x][y];
}
}
else if(d==2)
{
if(gr[x-1][y]==1)
{
if(l>1)
b=b+bo[x-1][y];
l=l-co[x-1][y];
d=1;
}
else
{
x--;
l=l-co[x][y];
}
}
else if(d==3)
{
if(gr[x][y-1]==1)
{
if(l>1)
b=b+bo[x][y-1];
l=l-co[x][y-1];
d=2;
}
else
{
y--;
l=l-co[x][y];
}
}
}
cout<<b<<endl;
t=t+b;
}
cout<<t<<endl;
return 0;
}
114! why me not ac
the code as follows, but the judge tell me Time limit exceeded
so, who can help me?
TKS
Code: Select all
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//ifstream cin("114.txt");
int edges[52][52];
int costs[52][52];
int values[52][52];
int wallCost;
int m,n,p;
cin>>m>>n;
cin>>wallCost;
cin>>p;
for(int i=0;i<m;i++){
edges[i][1]=-1;
edges[i][n]=-1;
}
for(int i=0;i<n;i++){
edges[1][i]=-1;
edges[n][i]=-1;
}// init the edges
int x,y,value,cost;
for(int i=0;i<p;i++){
scanf("%d%d%d%d",&x,&y,&value,&cost);
//cin>>x>>y>>value>>cost;
edges[n-y+1][x]=1;
values[n-y+1][x]=value;
costs[n-y+1][x]=cost;
}
int zx,zy,dir,leftTime;
int sumPoint=0;
while(scanf("%d%d%d%d",&zx,&zy,&dir,&leftTime)!=EOF){//cin>>zx>>zy>>dir>>leftTime
if(zx==0) break;
int totalPoints=0;
x=n-zy+1;
y=zx;
if(cin.eof()) break;
while(leftTime>0){
leftTime-=1;
if(leftTime<1) break;
int xnew,ynew;
switch(dir){
case 0:
xnew=x;ynew=y+1;break;
case 1:
xnew=x-1;ynew=y;break;
case 2:
xnew=x;ynew=y-1; break;
case 3:
xnew=x+1;ynew=y; break;
}
if(edges[xnew][ynew]!=0){
if(edges[xnew][ynew]==1) {totalPoints+=values[xnew][ynew];}
switch(dir){
case 0:
dir=3;break;
case 1:
dir=0;break;
case 2:
dir=1; break;
case 3:
dir=2; break;
}
if(edges[xnew][ynew]==1) leftTime-=costs[xnew][ynew];
else leftTime-=wallCost;
}
else{
x=xnew;
y=ynew;
}
}
cout<<totalPoints<<endl;
sumPoint+=totalPoints;
}
cout<<sumPoint<<endl;
}
TKS

Re: 114! why me not ac
Search the board first. There are already other discussions related to problem #114. Make your post in an existing thread.
Re: 114! why me not ac
thanks,I will search the same disscuss