40

csp小明放学,请求大佬帮忙指点错误

问题描述:提交只得了30分,但是自己太垃圾没明白是哪里出了问题

#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(){
    int r,y,g;
    int n;
    long long sum=0;
    vector<int> state;
    vector<int> time;
    scanf("%d %d %d",&r,&y,&g);
    scanf("%d",&n);
    int temp;
    for (int i=0;i<n;i++){
        scanf("%d",&temp);
        state.push_back(temp);
        scanf("%d",&temp);
        time.push_back(temp);
    }
    int sum1=0;
    for (int i=0;i<n;i++){
        if (state[i]==0){
            sum=sum+time[i];
        }
        else if (state[i]==1){
            sum1=sum%(r+y+g);
            if(sum1-time[i]<0){
                sum=sum+time[i]-sum1;
            }
            else if(sum1-time[i]<g&&sum1-time[i]>=0){

            }
            else if(sum1-time[i]<g+y&&sum1-time[i]>=g){
                sum=sum+y-sum1+time[i]+g+r;
            }
            else if (sum1-time[i]>=g+y&&sum1-time[i]<y+r+g){
                sum=sum+r-sum1+time[i]+g+y; 
            }
        }
        else if (state[i]==2) {
            sum1=sum%(r+y+g);
            if(sum1-time[i]<0){
                sum=sum+time[i]-sum1+r;
            }
            if(sum1-time[i]<r&&sum1-time[i]>=0){
                sum=sum+r-sum1+time[i];
            }
            if(sum1-time[i]<g+r&&sum1-time[i]>=r){
            }
            if (sum1-time[i]>=g+r&&sum1-time[i]<y+r+g){
                sum=sum+y+r+g-sum1+time[i]; 
            }
        }
        else if (state[i]==3){
            sum1=sum%(r+y+g);
            if(sum1-time[i]<0){
            }
            if(sum1-time[i]<y&&sum1-time[i]>=0){
                sum=sum+y-sum1+time[i]+r;
            }
            if(sum1-time[i]<y+r&&sum1-time[i]>=y){
                sum=sum+r+y-sum1+time[i];
            }
            if (sum1-time[i]>=y+r&&sum1-time[i]<y+r+g){

            }
        } 
    }
    printf("%lld",sum);
    return 0;
}
查看全部
qq_41104917
qq_41104917
2019/03/16 13:47
  • c++
  • c语言
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复