Showing posts with label LightOJ. Show all posts
Showing posts with label LightOJ. Show all posts
1118 - Incredible Molecules
Problem link: 1118 - Incredible Molecules
Topic: Geometry
Resources:
Robert Eisele
Matrix.Code
Code:
1049 - One Way Roads
1049 - One Way Roads
Topic: DFS
concept: কস্টকে ডিরেক্টটেড ধরবো তারপর আনডিক্টটেড গ্রাফ এ ডিএফএস চালাবো.
1263 - Equalizing Money
1263 - Equalizing Money
Topic: BFS
Concept: সব গুলা কম্পোনেন্ট এ চেক করবো সমান পরিমান টাকা আছে কিনা।
1387 - Setu
1387 - Setu
solution :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include<bits/stdc++.h> using namespace std; int main() { // freopen("in.txt", "r", stdin); int T; cin >> T; for(int cs = 1; cs <= T; ++cs){ long long ans = 0; int n; cin >> n; cout << "Case "<<cs<< ":\n"; while(n--){ string s; cin >> s; if(s == "donate"){ int x; cin >> x; ans += x; } else{ cout << ans<<endl; } } } } |
1225 - Palindromic Numbers (II)
1225 - Palindromic Numbers (II)
Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll Max = 100005; void palindrome(ll n, int cs) { ll test = n; ll ans = 0; while(n) { ans = ans*10 + n%10; n /= 10; } cout << "Case "<<cs<<": "; if(test == ans)cout << "Yes\n"; else cout << "No\n"; } int main() { ///* #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif //*/ int t; cin >> t; for(int cs = 1; cs <= t; cs++){ ll n; cin >> n; palindrome(n, cs); } //double end_time = clock(); //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000); return 0; } |
1202 - Bishops
1202 - Bishops
#include<bits/stdc++.h>
using namespace std;
#define MAX 2000100
typedef long long ll;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
//double start_time = clock();
int T;
cin>>T;
for(int i = 1; i <= T; i++)
{
ll r1,c1,r2,c2;
cin >> r1 >> c1 >> r2 >> c2;
if((r1+c1)%2 != (r2+c2)%2){
cout<<"Case "<<i<<": impossible\n";
}
else{
cout<<"Case "<<i<<": ";
if((r1+c1) == (r2+c2) || ((r1 - c1) == (r2 - c2)))cout << "1\n";
else cout << "2\n";
}
}
//double end_time = clock();
//printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
return 0;
}
1014 - Ifter Party
1014 - Ifter Party
Topic: Divisor
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include<bits/stdc++.h> using namespace std; typedef long long ll; set<int>V; int main() { //double start_time = clock(); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t; cin >> t; for(int cs = 1; cs <= t; cs++){ int p,l; cin >> p >> l; int ext = p - l; int sz = sqrt(ext); // cout << ext << " "<<sz<<endl; if(l < 1)V.insert(1); if(ext > l)V.insert(ext); for(int i = 2; i <= sz; i++){ if(ext%i == 0){ if(i*i == ext){ if(i > l)V.insert(i); } else{ if(i > l)V.insert(i); if(ext/i > l)V.insert(ext/i); } } } cout << "Case "<<cs<<":"; int tt = V.size(); if(tt == 0)cout << " impossible\n"; else{ for(auto it = V.begin(); it != V.end(); it++)cout << " "<<*it; cout << endl; } V.clear(); } return 0; } |
1136 - Division by 3
1136 - Division by 3
Explanation
#include<bits/stdc++.h>
using namespace std;
int cnt(int n)
{
if(n == 0)return 0;
int res = (n/3)*2;
if(n%3 == 2)res += 1;
return res;
}
int main()
{
int t;
cin >> t;
for(int cs = 1; cs <= t; cs++){
int a,b;
cin >> a >> b;
cout << "Case "<<cs << ": "<< cnt(b) - cnt(a - 1) <<endl;
}
return 0;
}
1182 - Parity
1182 - Parity
#include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for(int cs = 1; cs <= t; cs++){ int x; cin >> x; if(__builtin_parity(x))cout << "Case "<<cs<< ": odd\n"; else cout << "Case "<<cs<< ": even\n"; } return 0; }
1133 - Array Simulation
1133 - Array Simulation
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//map<int , int>M;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t;
cin >> t;
for(int cs = 1; cs <= t; cs++){
int n,m;
cin >> n >>m;
int a[n+2];
for(int i = 0; i < n; i++){
cin >> a[i];
}
while(m--){
char x;
int val;
cin >> x;
if(x == 'S'){
cin >> val;
for(int i = 0; i < n; i++)
a[i] += val;
//sum +=vall;
}
else if(x == 'M'){
cin >> val;
for(int i = 0; i < n; i++)
a[i] *= val;
//mul *= val;
}
else if(x == 'D'){
cin >> val;
for(int i = 0; i < n; i++)
a[i] /= val;
//div *= val;
}
else if(x == 'R'){
reverse(a, a+n);
}
else if(x == 'P'){
int y,z;
cin >> y >> z;
swap(a[y], a[z]);
}
//for(int i =0; i < n; i++)cout << a[i]<< " ";
// cout << endl <<"------------"<<endl;
}
cout << "Case "<<cs << ":\n";
for(int i = 0; i < n; i++){
cout << a[i];
if(i < n-1)cout << " ";
}
cout << endl;
}
return 0;
}
1116 - Ekka Dokka
1116 - Ekka Dokka
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int cs = 1; cs <= t; cs++){
long long w;
cin >> w;
if(w&1){
cout << "Case "<< cs<<": Impossible\n";
}
else{
for(long long i = 2; i <= w; i+=2){
long long x = w/i;
if(x&1 && (x*i) == w){
cout << "Case "<<cs<< ": "<<x<<" "<<i<<endl;
break;
}
}
}
}
return 0;
}