#include <stdio.h>#include <string.h>#include <stdlib.h>#define N 100#define M 1000typedefstruct node {
int s;
int e;
} TV;
int cmp(constvoid *a, constvoid *b)
{
return ((TV *)a)->e - ((TV *)b)->e;
}
int main(void)
{
int n, i, j;
TV b[N];
int m[M+1];
int tmax;
while (scanf("%d", &n) != EOF && n)
{
tmax = 0;
for(i=0; i<n; i++)
{
scanf("%d%d", &b[i].s, &b[i].e);
tmax = (b[i].e > tmax) ? b[i].e : tmax;
}
qsort(b, n, sizeof(b[0]), cmp);
memset(m, 0, sizeof(m));
for(i=0; i<n; i++)
{
int tmp = m[b[i].s]+1;
j = b[i].e;
m[j] = (tmp > m[j]) ? tmp : m[j];
for (j=b[i].e+1; j<=tmax; j++)
m[j] = m[j-1];
}
printf("%d\n", m[tmax]);
}
return0;
}
/**************************************************************
Problem: 1434
User: liangrx06
Language: C
Result: Accepted
Time:10 ms
Memory:912 kb
****************************************************************/
1435
#include <stdio.h>#include <stdlib.h>int cmp(constvoid *a, constvoid *b)
{
return *(int *)a - *(int *)b;
}
int main()
{
int i, c, n, v, w;
int p[100];
scanf("%d", &c);
while(c--)
{
scanf("%d %d %d", &n, &v, &w);
for (i=0; i<n; i++)
scanf("%d", &p[i]);
qsort(p, n, sizeof(p[0]), cmp);
double sum = 0;
for (i=0; i<n; i++)
{
double pnew = (sum+p[i])/(i+1);
if (pnew > w && pnew-w>1e-8)
break;
sum += p[i];
}
if (i == 0)
printf("0 0.00\n");
elseprintf("%d %.2lf\n", i*v, sum/i/100);
}
return0;
}
/**************************************************************
Problem: 1435
User: liangrx06
Language: C
Result: Accepted
Time:10 ms
Memory:912 kb
****************************************************************/
1436
#include <stdio.h>
#include <stdlib.h>
int cmp(constvoid *a, constvoid *b)
{
return *(int *)b - *(int *)a;
}
int main()
{
int i, n, w;
int p[600];
while(scanf("%d%d", &w, &n) != EOF)
{
for (i=0; i<n; i++)
scanf("%d", &p[i]);
qsort(p, n, sizeof(p[0]), cmp);
int sum = 0;
for (i=0; i<n; i++)
{
sum += p[i];
if (sum >= w)
break;
}
if (i == n)
printf("impossible\n");
else
printf("%d\n", i+1);
}
return0;
}
/**************************************************************
Problem: 1436
User: liangrx06
Language: C
Result: Accepted
Time:10 ms
Memory:912 kb
****************************************************************/
#include <stdio.h>
int gongyueshu(int a, int b)
{
if (b == 0) return a; return gongyueshu(b, a%b);
}
int main(void)
{
int a, b; while (scanf("%d%d", &a, &b) != EOF) { if (a <= b) { int tmp = a; a = b; b = tmp; } int gys = gongyueshu(a, b); printf("%d\n", gys * a/gys * b/gys); } return 0;
}
/**************************************************************
Problem: 1438 User: liangrx06 Language: C Result: Accepted Time:0 ms Memory:912 kb****************************************************************/
1439
#include <stdio.h>#include <stdlib.h>#include <ctype.h>#define M 100000#define N 100000int cmp(const void *a, const void *b)
{
return*(int*)a - *(int*)b;
}
void swap(int*x, int*y)
{
int tmp;
tmp = *x;
*x = *y;
*y = tmp;
}
int GCD(intx, inty)
{
if (y == 0)
returnx;
return GCD(y, x%y);
}
int LCM(intx, inty)
{
if (x == y)
returnx;
if (x < y)
swap(&x, &y);
int gcd = GCD(x, y);
returnx/gcd*y;
}
int main()
{
int i, j, t, n;
int a[N];
int lcm;
scanf("%d\n", &t);
for (i=0; i<t; i++)
{
scanf("%d", &n);
for (j=0; j<n; j++)
scanf("%d", &a[j]);
qsort(a, n, sizeof(n), cmp);
//for (j=0; j<n-1; j++)
// printf("%d ", a[j]);
//printf("%d\n", a[j]);
lcm = 1;
for (j=0; j<n; j++)
{
lcm = LCM(lcm, a[j]);
//printf("%d\n", lcm);
}
printf("%d\n", lcm);
}
return0;
}
/**************************************************************
Problem: 1439
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:1232 kb
****************************************************************/
1440
#include <stdio.h>
#include <math.h>
int isprime(int n) //n>=3, odd
{
int i;
for (i=3; i<=sqrt(n); i+=2)
{
if (n%i == 0)
return0;
}
return1;
}
int main()
{
int i, n;
int count;
while(scanf("%d", &n) != EOF && n)
{
if (n == 4)
{
printf("1\n");
continue;
}
count = 0;
for (i=3; i<=n/2; i+=2)
{
if (isprime(i) && isprime(n-i))
count ++;
}
printf("%d\n", count);
}
return0;
}
/**************************************************************
Problem: 1440
User: liangrx06
Language: C
Result: Accepted
Time:20 ms
Memory:928 kb
****************************************************************/