#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 n, st, sum; sf("%d", &test); for(t=1; t<=test; t++) { sf("%d", &n); sum=0; while(n--) { sf("%d", &st); if(st<=0) continue; sum+=st; } pf("Case %d: %d\n", t, sum); } return 0; }
Saturday, May 16, 2015
1015 - Brush (I) (Light OJ)
1069 - Lift (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 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; }
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;
- }
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 ...