This is an easy problem from uva judge http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1904
Adhoc.
How I did it
- Read the round number of cases.
- Read the number of columns.
- Get the absolute rest of the north and south row.
- If all the absolute values are equal print yes, otherwise print no.
Hints
- The row are infinite, don´t keep in mind.
- Just find the pattern.
Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <set> using namespace std; int main() { int casos, cols, northRow, southRow; scanf("%d", &casos); while(casos--) { scanf("%d", &cols); set<int> mySet; for(int x=0; x<cols; x++) { scanf("%d %d",&northRow, &southRow); mySet.insert(abs(northRow - southRow)); } if(mySet.size() == 1) printf("yes\n"); else printf("no\n"); if(casos) printf("\n"); } return 0; }