#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<vector> #include<map> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<(n); i++) #define MAX 100 int main() { int test, t; int m, l, ans; sf("%d", &test); for(t=1; t<=test; t++) { sf("%d %d", &m, &l); if(m==l) { ans = (m*4)+19; } else { ans = (abs(l-m)*4)+(m*4)+19; } pf("Case %d: %d\n", t, ans); } return 0; }
Saturday, May 16, 2015
1069 - Lift (Light OJ)
1053 - Higher Math (Light OJ)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<vector> #include<map> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<(n); i++) #define MAX 100 int main() { int test, t; int a, b, c; sf("%d", &test); for(t=1; t<=test; t++) { sf("%d %d %d", &a, &b, &c); if(((a*a)+(b*b))==(c*c) || ((b*b)+(c*c))==(a*a) || ((a*a)+(c*c))==(b*b)) pf("Case %d: yes\n", t); else pf("Case %d: no\n", t); } return 0; }
1006 - Hex-a-bonacci (LightOJ)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 10005
typedef long long ll;
ll fn[MAX];
int main()
{
int test, kase=0;
ll i, a, b, c, d, e, f, n;
cin >> test;
while(test--)
{
cin >> a >> b >> c >> d >> e >> f >> n;
fn[0] = a; fn[1] = b; fn[2] = c;
fn[3] = d; fn[4] = e; fn[5] = f;
for(i=6; i<=n; i++)
{
fn[i] = ((fn[i-1] + fn[i-2] + fn[i-3] + fn[i-4] + fn[i-5] + fn[i-6])%10000007 );
}
cout << "Case " << ++kase << ": " << (fn[n]%10000007) << endl;
}
return 0;
}
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 10005
typedef long long ll;
ll fn[MAX];
int main()
{
int test, kase=0;
ll i, a, b, c, d, e, f, n;
cin >> test;
while(test--)
{
cin >> a >> b >> c >> d >> e >> f >> n;
fn[0] = a; fn[1] = b; fn[2] = c;
fn[3] = d; fn[4] = e; fn[5] = f;
for(i=6; i<=n; i++)
{
fn[i] = ((fn[i-1] + fn[i-2] + fn[i-3] + fn[i-4] + fn[i-5] + fn[i-6])%10000007 );
}
cout << "Case " << ++kase << ": " << (fn[n]%10000007) << endl;
}
return 0;
}
Friday, May 15, 2015
462A - Appleman and Easy Task(Codeforces)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 105
typedef long long ll;
char a[MAX][MAX];
int d1[] = {0 , 0 , 1, -1};
int d2[] = {1, -1, 0, 0};
int n;
bool valid(int x, int y)
{
return (x>=0 && x<n && y>=0 && y<n);
}
int main()
{
int i, j, k;
int x, y, cnt=0, flag=1;
sf("%d", &n);
loop(i, n)
sf("%s", a[i]);
loop(i, n)
{
loop(j, n)
{
loop(k, 4)
{
x = d1[k] + i;
y = d2[k] + j;
if(!valid(x, y))
continue;
if(a[x][y]== 'o')
cnt++;
}
if(cnt & 1)
{
flag = 0;
i = j = n+n;
}
}
}
if(flag==1)
pf("YES\n");
else
pf("NO\n");
return 0;
}
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 105
typedef long long ll;
char a[MAX][MAX];
int d1[] = {0 , 0 , 1, -1};
int d2[] = {1, -1, 0, 0};
int n;
bool valid(int x, int y)
{
return (x>=0 && x<n && y>=0 && y<n);
}
int main()
{
int i, j, k;
int x, y, cnt=0, flag=1;
sf("%d", &n);
loop(i, n)
sf("%s", a[i]);
loop(i, n)
{
loop(j, n)
{
loop(k, 4)
{
x = d1[k] + i;
y = d2[k] + j;
if(!valid(x, y))
continue;
if(a[x][y]== 'o')
cnt++;
}
if(cnt & 1)
{
flag = 0;
i = j = n+n;
}
}
}
if(flag==1)
pf("YES\n");
else
pf("NO\n");
return 0;
}
Thursday, May 14, 2015
459A - Pashmak and Garden(Codeforces)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 100
int main()
{
int x1, x2, x3, x4;
int y1, y2, y3, y4;
int d;
while(sf("%d%d%d%d", &x1 , &y1, &x2, &y2)==4)
{
if(x1==x2)
{
d = abs(y2-y1);
y3 = y1;
y4 = y2;
x3 = x1 + d;
x4 = x2 + d;
}
else if(y1==y2)
{
d = abs(x2-x1);
x3 = x1;
x4 = x2;
y3 = y1+d;
y4 = y2+d;
}
else if(abs(x2-x1)==abs(y2-y1))
{
x3 = x1;
y3 = y2;
x4 = x2;
y4 = y1;
}
else
{
pf("-1\n");
continue;
}
pf("%d %d %d %d\n", x3, y3, x4, y4);
}
return 0;
}
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 100
int main()
{
int x1, x2, x3, x4;
int y1, y2, y3, y4;
int d;
while(sf("%d%d%d%d", &x1 , &y1, &x2, &y2)==4)
{
if(x1==x2)
{
d = abs(y2-y1);
y3 = y1;
y4 = y2;
x3 = x1 + d;
x4 = x2 + d;
}
else if(y1==y2)
{
d = abs(x2-x1);
x3 = x1;
x4 = x2;
y3 = y1+d;
y4 = y2+d;
}
else if(abs(x2-x1)==abs(y2-y1))
{
x3 = x1;
y3 = y2;
x4 = x2;
y4 = y1;
}
else
{
pf("-1\n");
continue;
}
pf("%d %d %d %d\n", x3, y3, x4, y4);
}
return 0;
}
Thursday, May 7, 2015
1043 - Triangle Partitioning (Light OJ)
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- long long test, t;
- double AB, AC, BC, AD, ratio, ratio2;
- scanf("%lld", &test);
- for(t=1; t<=test; t++)
- {
- scanf("%lf%lf%lf%lf", &AB, &AC, &BC, &ratio);
- ratio2 =ratio/(ratio+1);
- AD = AB*sqrt(ratio2);
- printf ("Case %lld: %lf\n", t, AD);
- }
- return 0;
- }
1012 - Guilty Prince (Light OJ)
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<queue>
- #include<cstring>
- using namespace std;
- typedef pair<int,int> pii;
- #define pf printf
- #define sf scanf
- #define MAX 1000
- char grid[50][50];
- bool vis[50][50];
- queue <pii> Q;
- int r , c;
- int dx[] = {0, 0, -1, 1};
- int dy[] = {-1, 1, 0, 0};
- bool valid(int x,int y)
- {
- return x>=0 && y>=0 && x<r && y<c && (grid[x][y]=='.');
- }
- int bfs(int x, int y)
- {
- int ux, uy, vx, vy, cnt=0;
- memset(vis, 0, sizeof(vis));
- while(!Q.empty()) Q.pop(); //queue clear
- vis[x][y] = true;
- Q.push(pii(x,y));
- while(!Q.empty())
- {
- pii u = Q.front(); Q.pop();
- ux = u.first; uy = u.second;
- for(int i=0; i<4 ;i++)
- {
- vx = ux + dx[i];
- vy = uy + dy[i];
- if(!valid(vx, vy)) continue;
- if(vis[vx][vy]) continue;
- cnt++;
- vis[vx][vy] = true;
- Q.push(make_pair(vx, vy));
- }
- }
- return cnt;
- }
- int main()
- {
- //freopen("in.txt", "r", stdin);
- int sr, sc, kase=0;
- int test, t;
- int i, j;
- sf("%d", &test);
- while(test--)
- {
- sf("%d%d", &c, &r);
- for(i=0; i<r; i++)
- sf("%s", grid[i]);
- for(i=0; i<r; i++)
- for(j=0; j<c; j++)
- if(grid[i][j]=='@')
- sr = i , sc = j, i = j = c+r;
- int ans = bfs(sr, sc)+1;
- pf("Case %d: %d\n", ++kase, ans);
- }
- return 0;
- }
Subscribe to:
Posts (Atom)
Compare equality of two string in C
#include <stdio.h> #include<string.h> int main() { char* country = "Bangladesh"; char* country2; ...
-
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespac...
-
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<ve...
-
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; #define pf printf ...