JIAN_BOY_RISE 2016-09-12 06:13 采纳率: 37.5%
浏览 1436
已采纳

acm 总是Time Limit Exceed!!!!!!!!!!!

Description

The 36th ACM match was hosted in Chengdu in 2011 Nov 4. There is an interesting rule in ACM match that once you solve a problem, you'll get a balloon.

To simplify these names, we just name these teams S1, S2, S3 ... SN.

We want to know how many balloons they get between team Si and Sj (including Si and Sj). We may ask many times. It is too boring to count every time.

Since you are a programmer, can you write a program to solve it?

Input

First is an integer N (1 <= N <= 140) indicates the number of schools.

Followed with an integer M (1 <= M <= 50000) indicates the number of operations.

There are two kinds of operations.

AC X

     Means team SX solve a problem and will get a balloon.

COUNT X Y

     Means count balloons of team between SX and SY

Output

For each operation "COUNT X Y" output the number you count

Sample Input
5 4
AC 1
COUNT 1 3
AC 2
COUNT 1 3
Sample Output
1
2

我的程序:
#include
#include
#include
using namespace std;
int main()
{
int b,a;
scanf("%d%d",&b,&a);
int *c=new int[b];
for(int j=0;j {
c[j]=0;
}
while(a--)
{
string d;
int g,p,f;
cin>>d;
if(d=="AC")
{
scanf("%d",&g);
c[g-1]++;
}else if(d=="COUNT")
{
scanf("%d%d",&p,&f);
int sum=0;
for(int i=p-1;i<f;i++)
{
sum+=c[i];
}
printf("%d\n",sum);
}

}
return 0;
}

  • 写回答

4条回答 默认 最新

  • 祈祷爱绝缘 2016-09-13 08:14
    关注

    反正闲着没事,就去你们矿业大学的ACM注册了个账户,用java写了一个,你可以参考一下

    import java.util.*;
    
    public class Main {
        public static void main(String[] args) {
    
            Scanner in = new Scanner(System.in);
    
            while (in.hasNext()) {
                int schools = in.nextInt();// 学校数
                int operations = in.nextInt();// 操作数
                int[] arr = new int[schools + 1];// 数组
                for (int i = 0; i < operations; i++) {
                    String oper = in.next();
                    if (oper.equals("AC")) {
                        int school = in.nextInt();
                        // 从当前学校往后的所有学校都加一
                        for (int j = school; j < schools + 1; j++) {
                            arr[j]++;
                        }
                    } else {
                        int first = in.nextInt();
                        int second = in.nextInt();
                        System.out.println(arr[second] - arr[first - 1]);
                    }
                }
            }
        }
    }
    
    
    

    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能