/* User ID: turing_13 Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3593 */ #include <bits/stdc++.h> #define pii pair <int,int> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define oo 1<<29 #define dd double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define MAX 100 #define SZ(a) (int)a.size() #define getint(a) scanf("%d",&a) #define loop(i,n) for(int i=0;i<n;i++) #define all(a) a.begin(),a.end() #define intlim 2147483648 #define inf 1000000 #define rtintlim 46340 #define llim 9223372036854775808 #define rtllim 3037000499 #define ull unsigned long long #define I int using namespace std; ll ara[4010][4]; vector<ll>ab; int main() { ///freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int n,t; sc("%d",&t); while(t--) { ll ans=0; sc("%d",&n); for(int i=0; i<n; i++) { sc("%lld %lld %lld %lld",&ara[i][0],&ara[i][1],&ara[i][2],&ara[i][3]); } for(int i=0; i<n; i++) for(int j=0; j<n; j++) { ab.pb(ara[i][0]+ara[j][1]); } sort(all(ab)); for(int i=0; i<n; i++) for(int j=0; j<n; j++) { int val= -(ara[i][2]+ara[j][3]); ans+= upper_bound(all(ab),val)-lower_bound(all(ab),val); } pf("%lld\n",ans); if(t) pf("\n"); ab.clear(); } return 0; }
Category Archives: Ad Hoc
UVa 11608 – No Problem
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2655
/* If opportunity doesn't knock, build a door. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |S|.|S|.|R|.|A|.|S|.|A|.|M|.|K| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Success is how high you bounce when you hit bottom. */ #include <bits/stdc++.h> #define pii pair <int,int> #define pll pair <long long,long long> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 1000000007 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define stlloop(v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define RREP(i,a,b) for(int i=a;i>=b;i--) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<":"<<endl #define all(a) a.begin(),a.end() #define intlim 2147483648 #define infinity (1<<28) #define ull unsigned long long #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*((b)/gcd(a,b))) using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ int main() { // freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int n,s; int z=0; while(cin>>n && n>=0) { z++; int ara1[15],ara2[15]; loop(i,12) cin>>ara1[i]; loop(i,12) cin>>ara2[i]; CASE_PRINT; loop(i,12) { if(n>=ara2[i]) { cout<<"No problem! :D"<<endl; n-=ara2[i]; } else { cout<<"No problem. :("<<endl; } n+=ara1[i]; } } return 0; }
UVa 993 – Product of digits
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=934
Solution Idea:
Just divide the number by integers 9,8,7,6,5,4,3 and 2 and when we can divide the digit with a number then we can add it to a string. and at last if The last number is greater than 9 then we can’t express that number in that way. So the ans will be -1 and If we can divide the whole number by 9 to 2 then after all division we need to reverse the string because we have to print minimum number.
/* If opportunity doesn't knock, build a door. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |S|.|S|.|R|.|A|.|S|.|A|.|M|.|K| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Success is how high you bounce when you hit bottom. */ #include <bits/stdc++.h> #define pii pair <int,int> #define pll pair <long long,long long> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 1000000007 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define stlloop(v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define RREP(i,a,b) for(int i=a;i>=b;i--) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<": " #define all(a) a.begin(),a.end() #define intlim 2147483648 #define infinity (1<<28) #define ull unsigned long long #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*((b)/gcd(a,b))) using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ int main() { // freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int t; cin>>t; TEST_CASE(t) { int n; cin>>n; if(n<10) { cout<<n<<endl; continue; } string str; int last=-1; while(n>1 && last!=n) { last=n; for(int i=9; i>=2; i--) { if(n%i==0) { while(n%i==0) { n/=i; str+='0'+i; } } } } reverse(all(str)); if(n>1) cout<<-1<<endl; else cout<<str<<endl; } return 0; }
UVa 11850 – Alaska
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2950
Solution Idea:
The tricky part in this problem statement is this –
” Can Brenda drive her car from Dawson City to Delta Junction and back? ”
So Brenda need to reach her destination and return his start point. So just take input all the points and sort then in acceding order and check that the distance between two consecutive points is less than or equal to 200 or not. If it’s not then the ans will be impossible and if the 2*(distance between the last point and and destination) >200 the ans will be impossible. Otherwise the ans is possible.
/* If opportunity doesn't knock, build a door. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |S|.|S|.|R|.|A|.|S|.|A|.|M|.|K| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Success is how high you bounce when you hit bottom. */ #include <bits/stdc++.h> #define pii pair <int,int> #define pll pair <long long,long long> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 1000000007 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define stlloop(v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define RREP(i,a,b) for(int i=a;i>=b;i--) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<": " #define all(a) a.begin(),a.end() #define intlim 2147483648 #define infinity (1<<28) #define ull unsigned long long #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*((b)/gcd(a,b))) using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ int main() { // freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int n; while(cin>>n && n) { vector<int>v; loop(i,n) { int a; cin>>a; v.pb(a); } sort(all(v)); bool test=0; REP(i,1,n) { if(v[i]-v[i-1]>200) { cout<<"IMPOSSIBLE"<<endl; test=1; break; } } if(test==1) continue; if((1422-v[n-1])*2>200) test=1; if(test==0) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; } return 0; }
UVa 11734 – Big Number of Teams will Solve This
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2834
/* +-+ +-+ +-+ |R| |.| |S| +-+ +-+ +-+ */ #include <bits/stdc++.h> #define pii pair <int,int> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 100007 #define MAX 10000 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<": " #define all(a) a.begin(),a.end() #define intlim 2147483648 #define inf 1000000 #define ull unsigned long long using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ int main() { ///freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int t; cin>>t; getchar(); TEST_CASE(t) { string s1,s2; getline(cin,s1); getline(cin,s2); CASE_PRINT; if(s1==s2) { cout<<"Yes"<<endl; } else { string s3; loop(i,SZ(s1)) { if(s1[i]!=' ') s3+=s1[i]; } if(s3==s2) cout<<"Output Format Error"<<endl; else cout<<"Wrong Answer"<<endl; } } return 0; }
UVa 11799 – Horror Dash
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2899
/* +-+ +-+ +-+ |R| |.| |S| +-+ +-+ +-+ */ #include <bits/stdc++.h> #define pii pair <int,int> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 100007 #define MAX 10000 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<": " #define all(a) a.begin(),a.end() #define intlim 2147483648 #define inf 1000000 #define ull unsigned long long using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ int main() { ///freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int t; sf(t); TEST_CASE(t) { int n; sf(n); int maxi=-10000,a; loop(i,n) cin>>a,maxi=max(maxi,a); CASE_PRINT; cout<<maxi<<endl; } return 0; }
UVa 11797 – Drutojan Express
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2897
Solution Idea:
This is an interesting simulation problem. Read the problem statement carefully and try to simulate the problem using programming.
/* +-+ +-+ +-+ |R| |.| |S| +-+ +-+ +-+ */ #include <bits/stdc++.h> #define pii pair <int,int> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 100007 #define MAX 10000 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<":"<<endl; #define all(a) a.begin(),a.end() #define intlim 2147483648 #define inf 1000000 #define ull unsigned long long using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ int ara[10]; string sss[7]={"Ja", "Sam", "Sha", "Sid", "Tan"}; int main() { CIN; ///freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); map<string, int>mp; mp["Ja"]=0; mp["Sam"]=1; mp["Sha"]=2; mp["Sid"]=3; mp["Tan"]=4; int t; cin>>t; TEST_CASE(t) { ms(ara,0); int m,n; string str; cin>>m>>n>>str; deque<string> Q[6]; loop(i,5) { int k; cin>>k; loop(j,k) { string s1; cin>>s1; Q[i].push_back(s1); } } while(n>0) { if(m>n) { ara[mp[str]]+=n; n=0; break; } else { int xx=mp[str]; ara[xx]+=m; n-=m; n-=2; str=Q[xx].front(); Q[xx].push_back(Q[xx].front()); Q[xx].pop_front(); } } CASE_PRINT; for(int i=0;i<5;i++) { cout<<sss[i]<<" "<<ara[i]<<endl; } loop(i,6) Q[i].clear(); } return 0; }
UVa 11805 – Bafana Bafana
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2905
/* +-+ +-+ +-+ |R| |.| |S| +-+ +-+ +-+ */ #include <bits/stdc++.h> #define pii pair <int,int> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 100007 #define MAX 10000 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<": " #define all(a) a.begin(),a.end() #define intlim 2147483648 #define inf 1000000 #define ull unsigned long long using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ int main() { ///freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int t; cin>>t; TEST_CASE(t) { int n,k,p; cin>>n>>k>>p; CASE_PRINT; int ans=(k+((p)%n))%n; if(ans==0) ans=n; cout<<ans<<endl; } return 0; }
UVa 11804 – Argentina
0Problem Link : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2904
Solution Idea:
Just simulation. Sort the inputs as described in the problem statement.
/* +-+ +-+ +-+ |R| |.| |S| +-+ +-+ +-+ */ #include <bits/stdc++.h> #define pii pair <int,int> #define sc scanf #define pf printf #define Pi 2*acos(0.0) #define ms(a,b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define db double #define ll long long #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x)*(x) #define D(x) cout<<#x " = "<<(x)<<endl #define VI vector <int> #define DBG pf("Hi\n") #define MOD 100007 #define MAX 10000 #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define SZ(a) (int)a.size() #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define loop(i,n) for(int i=0;i<n;i++) #define REP(i,a,b) for(int i=a;i<b;i++) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define CASE_PRINT cout<<"Case "<<z<<":"<<endl; #define all(a) a.begin(),a.end() #define intlim 2147483648 #define inf 1000000 #define ull unsigned long long using namespace std; /*----------------------Graph Moves----------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ /*-----------------------Bitmask------------------*/ //int Set(int N,int pos){return N=N | (1<<pos);} //int reset(int N,int pos){return N= N & ~(1<<pos);} //bool check(int N,int pos){return (bool)(N & (1<<pos));} /*------------------------------------------------*/ struct data { string name; int attack, defence; }; bool cmp1(data a, data b) { if(a.attack>b.attack) return 1; else if(a.attack<b.attack) return 0; else { if(a.defence<b.defence) return 1; else if(a.defence>b.defence) return 0; else return a.name<b.name; } } bool cmp2(data a, data b) { return a.name<b.name; } int main() { ///freopen("in.txt","r",stdin); ///freopen("out.txt","w",stdout); int t; cin>>t; TEST_CASE(t) { vector<data> v,vv,vvv; loop(i,10) { data temp; cin>>temp.name; cin>>temp.attack>>temp.defence; v.pb(temp); } sort(all(v),cmp1); for(int i=0;i<10;i++) { // D(v[i].name); // D(v[i].attack); // D(v[i].defence); if(i<5) vv.pb(v[i]); else vvv.pb(v[i]); } sort(all(vv),cmp2); sort(all(vvv),cmp2); CASE_PRINT; cout<<"("; loop(i,5) { if(i) cout<<", "; cout<<vv[i].name; } cout<<")"<<endl; cout<<"("; loop(i,5) { if(i) cout<<", "; cout<<vvv[i].name; } cout<<")"<<endl; } return 0; }
UVa : 579 – Clock Hands
0/* User ID: turing_13 Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=520 */ #include <stdio.h> #include <math.h> int main () { double time,angle,hour,min; char a; while(scanf("%lf %c %lf", &hour,&a,&min) != EOF) { if(hour==0.00 && min==0.00) break; angle=(min*6)-(hour*30)-(min/2); if(angle<0) angle=360+angle; if(angle>180) angle=360-angle; printf("%.3lf\n", angle); } return 0; }