ZCO-2019::SINGTOUR(incomplete)
#include <iostream>
using namespace std ;
int main(){
int t ;
cin >> t ;
while (t--){
int n ;
cin >> n ;
int lower_limit[n];
int upper_limit[n];
int no_of_pitches[n] ;
int points[n] ;
for (int i = 0; i < n; ++i) {
cin >> lower_limit[i] >> upper_limit[i] ;
no_of_pitches[i] = upper_limit[i] - lower_limit[i] + 1 ;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n -1; ++j) {
if (no_of_pitches[j] > no_of_pitches[j+1]){
points[j] = 2 ;
points[j+1] = 0 ;
} else{
points[i] = 1 ;
points[i+1] = 1 ;
}
}
cout << points[i] << '\n' ;
}
}
return 0;
}
ALTER:
//logic: if a is subset of b then b wins and a loses , if a is not a subset of b then
//its a draw.
#include <iostream>
using namespace std ;
int main(){
int t ;
cin >> t ;
while (t--){
int n ;
cin >> n ;
int lowest_pitch[n] ;
int highest_pitch[n] ;
int length[n];
for (int i = 0; i < n; ++i) {
cin >> lowest_pitch[i] >> highest_pitch[i] ;
length[i] = highest_pitch[i] - lowest_pitch[i] + 1 ;
}
for (int i = 0; i < n; ++i) {
int all_pitches[n][length[i]];
while (lowest_pitch[i] <= highest_pitch[i]) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < length[i]; ++k) {
all_pitches[j][k] = lowest_pitch[i];
lowest_pitch[i]++;
}
}
}
for (int j = 0; j < n; ++j) {
for (int k = 0; k < length[i]; ++k) {
cout << all_pitches[j][k] << " " << '\n';
}
}
}
return 0;
}}
ALTER:
//logic: if a is subset of b then b wins and a loses , if a is not a subset of b then
//its a draw.
#include <iostream>
using namespace std ;
int main(){
int t ;
cin >> t ;
while (t > 0){
int n ;
cin >> n ;
int lowest_pitch[n] ;
int highest_pitch[n] ;
int length[n];
for (int i = 0; i < n; ++i) {
cin >> lowest_pitch[i] >> highest_pitch[i] ;
length[i] = highest_pitch[i] - lowest_pitch[i] + 1 ;
}
int largest{INT16_MIN};
for (int i = 0; i < n; ++i) {
if (length[i] > largest){
largest = length[i];
}
}
int all_pitches[n][largest];
for (int i = 0; i < n; ++i) {
while (lowest_pitch[i] <= highest_pitch[i]) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < largest; ++k) {
all_pitches[j][k] = lowest_pitch[i];
lowest_pitch[i]++;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < largest; ++j) {
cout << all_pitches[i][j] << '\n' ;
}
}
}
t -- ;
}
return 0 ;
}
Comments
Post a Comment