CSU 1336: Interesting Calculator 1339: 最后一滴血 1350: To Add Which?

1336: Interesting Calculator

#include
#include
#include
#include
#define maxn 100050
#define INF 0x3f3f3f3f
using namespace std;
int cost[3][10];
int dis[maxn],num[maxn];
int vis[maxn];
int st,ed;
int Case=1;
void spfa()
{
    memset(dis,INF,sizeof(dis));
    memset(vis,0,sizeof(vis));
    queue<int>q;
    int u,v,t;
    q.push(st);
    num[st]=dis[st]=0;
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        vis[u]=0;
        for(int i=0; i<3; i++)
            for(int j=0; j<10; j++)
            {
                if(i==0)
                    v=u*10+j;
                else if(i==1)
                    v=u+j;
                else
                    v=u*j;
                if(v>ed)                //注意是break  +1 *1  *10+1  都爆了 就不用考虑后面那些了
                    break;
                if(dis[v]<=dis[u]+cost[i][j])
                    continue;
                dis[v]=dis[u]+cost[i][j];
                num[v]=num[u]+1;
                if(!vis[v])
                {
                    vis[v]=1;
                    q.push(v);
                }
            }
    }
    printf("Case %d: %d %d\n",Case++,dis[ed],num[ed]);
}
int main()
{
    while(~scanf("%d%d",&st,&ed))
    {
        for(int i=0; i<3; i++)
            for(int j=0; j<10; j++)
                scanf("%d",&cost[i][j]);
        spfa();
    }
    return 0;
}


/**********************************************************************
	Problem: 1336
	User: 3901140225
	Language: C++
	Result: AC
	Time:228 ms
	Memory:3592 kb
**********************************************************************/

1339: 最后一滴血

#include
#include
#include
using namespace std;
struct node{
    int time,id;
}q[20];
int d[20][105];

int main()
{
    int n,t,m;
    cin>>n>>t>>m;
    int ans=0;
    for(int i=0;i<12;i++)
    {
        q[i].time=-1;
        q[i].id=0;
    }
    memset(d,0,sizeof(d));
    for(int i=0;ichar a,b[10];
        int time,c;
        cin>>time>>c>>a>>b;         
        int tt=a-'A';
        ans=max(ans,tt);
        if(b[0]=='Y')
        {
            if(q[tt].time<=time)
            {
                if(d[tt][c]==0)
                {
                    q[tt].time=time;
                    q[tt].id=c;
                    d[tt][c]=1;
                }
            }
        }
    } 
    for(int i=0;i<=ans;i++)
    {
        printf("%c ",i+'A');
        if(q[i].time!=-1)
          printf("%d %d",q[i].time,q[i].id);
        else
          printf("- -");
        printf("\n");
    }
    return 0;
} 
/**********************************************************************
	Problem: 1339
	User: 3901140225
	Language: C++
	Result: AC
	Time:0 ms
	Memory:2032 kb
**********************************************************************/

1350: To Add Which?


#include
#include
#define M 100100
using namespace std;

int num[M],Max[M],Min[M];

int max(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    int T,n,D;
    long long ans;
    cin>>T;
    while(T--){
        ans=0;
        cin>>n>>D;
        for(int i=0;icin>>num[i];

        Max[0]=num[0];
        for(int i=1;iif(Max[i-1]-num[i]>D)
                Max[i]=Max[i-1]-D;
            else Max[i]=num[i];
        }

        Min[n-1]=num[n-1];
        for(int i=n-2;i>=0;i--)
        {
            if(Min[i+1]-num[i]>D)
                Min[i]=Min[i+1]-D;
            else Min[i]=num[i];
        }

        for(int i=0;icout<endl;
    }
    return 0;
}
/**********************************************************************
	Problem: 1350
	User: 3901140225
	Language: C++
	Result: AC
	Time:492 ms
	Memory:3196 kb
**********************************************************************/

你可能感兴趣的:(CSU 1336: Interesting Calculator 1339: 最后一滴血 1350: To Add Which?)