C - Free Food

Do you know what attracts almost any college student to participate in an event? Yes, free food. It doesn’t matter whether the event involves a long (sometimes boring) seminar. As long as free food is served for the event, then students will surely come.

Suppose there are N
events to be held this year. The ith event is scheduled from day si to day ti, and free food is served for that event every day from day si to day ti

(inclusive). Your task in this problem is to find out how many days there are in which free food is served by at least one event.

For example, let there be N=3
events. The first event is held from day 10 to 14, the second event is held from day 13 to 17, and the third event is held from day 25 to 26. The days in which free food is served by at least one event are 10,11,12,13,14,15,16,17,25,26, for a total of 10 days. Note that both events serve free food on days 13 and 14

.
Input

The first line contains an integer N
(1≤N≤100) denoting the number of events. Each of the next N lines contains two integers si and ti (1≤si≤ti≤365) denoting that the ith event will be held from si to ti

(inclusive), and free food is served for all of those days.
Output

The output contains an integer denoting the number of days in which free food is served by at least one event.
Sample Input 1 Sample Output 1

3
10 14
13 17
25 26

10

Sample Input 2 Sample Output 2

2
1 365
20 28

365

Sample Input 3 Sample Output 3

4
29 29
48 48
102 102
94 94

4

#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    int t, n, a[370], x, y, i;
    int c;
    scanf("%d", &t);
    memset(a, 0, sizeof(a));
    c = 0;
    while(t--)
    {
        scanf("%d %d", &x, &y);
        for(i=x;i<=y;i++)
        {
            if(a[i]==0)
            {
                c++;
                a[i] = 1;
            }
        }
    }
    printf("%d\n", c);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
![libplctag CI](https://github.com/libplctag/libplctag/workflows/libplctag%20CI/badge.svg?branch=release) **libplctag** is an open source C library for Linux, Windows and macOS using **EtherNet/IP** or **Modbus TCP** to read and write tags in PLCs. The library has been in production since early 2012 and is used by multiple organizations for many tasks including controlling radio telescopes, large and precision manufacturing, controlling fitness equipment, food handling and many, many more. Current Stable Version: 2.5 Old Stable Version: 2.4 ## WARNING - DISCLAIMER Note: **PLCs control many kinds of equipment and loss of property, production or even life can happen if mistakes in programming or access are made. Always use caution when accessing or programming PLCs!** We make no claims or warrants about the suitability of this code for any purpose. Be careful! ## Get It Do you know what you want already? Download it from the [releases page](https://github.com/libplctag/libplctag/releases)! ## Features ### High Level Features - EtherNet/IP and Modbus TCP support. - Open source licensing under the MPL 2.0 or LGPL 2+. - Pure C library for portability across Linux, Windows and macOS as well as 32-bit and 64-bit. - Support for x86, ARM and MIPS, and probably others. - Very stable API with almost no changes other than feature additions since 2012. - Low memory use and very high performance and capacity. Uses protocol-specific features to increase performance. - Simple API with minimal use of language-specific data to enable easy wrapping in other languages. - Extensive example programs showing use of all library features. - Wrappers for higher level languages like C#/.Net, Julia etc. - Free! ### Detailed Features
07-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值