1 solutions
-
0
C++ :
#include<iostream> #include <algorithm> using namespace std; const int NN = 10001; void Process(bool trees[], int start, int end) { for (int i=start; i<=end; i++) trees[i] = false; } int main() { int L, M, i; bool trees[NN]; int start, end; while(cin>>L >>M) { for (i=0; i <= L; i++) { if (i%2 == 0) trees[i] = true; else trees[i] = false; } for (i=0; i<M; i++) { cin>>start >>end; Process(trees, start, end); } cout<<count(trees, trees+L+1, true)<<endl; } return 0; }Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); while(input.hasNextInt()){ int L = input.nextInt(); int M = input.nextInt(); int i,j; int[][] area = new int[M][2]; int[] tree = new int[L+1]; int treeNum = 0; for(i = 0; i < M; i++){ for(j = 0; j < 2; j++){ area[i][j] = input.nextInt(); } for(j = area[i][0]; j <= area[i][1]; j++){ if(j % 2 == 0 && tree[j] != 1){ tree[j] = 1; treeNum++; } } } int treeSum = L / 2 + 1; int leftTree = treeSum - treeNum; System.out.println(leftTree); } } }
- 1
Information
- ID
- 16800
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By