1541(未完成)
1542(未完成)
1543
#include <stdio.h>
#include <limits.h>
typedef unsigned long long ULL;
int getb(ULL n, int i)
{
n >>= i;
return n%2;
}
ULL setb(ULL n, int i, ULL k)
{
k <<= i;
n |= k;
return n;
}
int main(void)
{
int t, i, k;
ULL n, p, q;
int type;
scanf("%d", &t);
while (t--)
{
scanf("%d", &type);
if (type == 1)
{
scanf("%llu", &n);
p = 1;
q = 1;
for (k=63; k>=0; k--)
{
if (getb(n, k))
break;
}
for (i=k-1; i>=0; i--)
{
if (getb(n, i))
p += q;
else
q += p;
}
printf("%llu %llu\n", p, q);
}
else
{
scanf("%llu%llu", &p, &q);
n = 0;
for (i=0; i<64; i++)
{
if (p + q == 1)
{
break;
}
if (p < q)
{
n = setb(n, i, 0);
q -= p;
}
else
{
n = setb(n, i, 1);
p -= q;
}
}
printf("%llu\n", n);
}
}
return 0;
}
1544
int a[N];
int seg[4*N];
int Min(int x, int y)
{
return (x < y) ? x : y;
}
void create(int i, int b, int e)
{
if (b == e)
{
seg[i] = a[b];
return ;
}
create(2*i, b, (b+e)/2);
create(2*i+1, (b+e)/2+1, e);
seg[i] = Min(seg[2*i], seg[2*i+1]);
}
int query(int i, int b, int e, int l, int r)
{
if (b > r || e < l)
return INF;
if (l <= b && e <= r)
return seg[i];
int m1 = query(2*i, b, (b+e)/2, l, r);
int m2 = query(2*i+1, (b+e)/2+1, e, l, r);
return Min(m1, m2);
}
int main(void)
{
int t, n, i, m;
int l, r;
while (scanf("%d", &n) != EOF)
{
for (i=0; i<n; i++)
scanf("%d", &a[i]);
create(1, 0, n-1);
scanf("%d", &t);
for (i=0; i<t; i++)
{
scanf("%d%d", &l, &r);
m = query(1, 0, n-1, l-1, r-1);
printf("%d\n", m);
}
}
return 0;
}
/**************************************************************
Problem: 1544
User: liangrx06
Language: C
Result: Accepted
Time:260 ms
Memory:2868 kb
****************************************************************/
1545
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 10000
#define M 100000
typedef struct node {
int x;
int y;
int d;
} ROAD;
int n;
int pre[N+1];
int count[N+1];
int num;
void init()
{
for (int i=1; i<=n; i++)
{
pre[i] = i;
count[i] = 1;
}
num = n;
}
int find(int i)
{
while (i != pre[i])
i = pre[i];
return i;
}
int combine(int i, int j)
{
int a = find(i);
int b = find(j);
if (a != b)
{
if (count[a] > count[b])
{
pre[b] = a;
count[a] += count[b];
count[b] = 0;
}
else
{
pre[a] = b;
count[b] += count[a];
count[a] = 0;
}
num --;
return 1;
}
else
return 0;
}
int cmp(const void *a, const void *b)
{
ROAD *x = (ROAD *)a;
ROAD *y = (ROAD *)b;
return x->d - y->d;
}
int main(void)
{
int m, i;
ROAD r[M];
int max, flag;
while (scanf("%d%d", &n, &m) != EOF)
{
for (i=0; i<m; i++)
scanf("%d%d%d", &r[i].x, &r[i].y, &r[i].d);
qsort(r, m, sizeof(r[0]), cmp);
init();
max = 0;
flag = 0;
for(i=0; i<m; i++)
{
if(combine(r[i].x, r[i].y))
max = r[i].d;
if (find(1) == find(n))
{
flag = 1;
break;
}
}
if (flag == 0)
printf("-1\n");
else
printf("%d\n", max);
}
return 0;
}
1546(未完成)
1547
//h(n)=h(n-1)*(4*n-2)/(n+1);
//h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2)
//h(n)=c(2n,n)/(n+1)
//h(n)=c(2n,n)-c(2n,n+1)
int main()
{
int i, j, n;
long long a[1001];
//for (n=2; n<=1000; n+=2)
while(scanf("%d", &n) != EOF)
{
if (n%2 != 0)
{
printf("0\n");
continue;
}
a[0] = a[1] = 1;
for (i=2; i<=n/2; i++)
{
a[i] = 0;
for (j=0; j<i; j++)
a[i] += (a[j]*a[i-1-j])%M;
a[i] %= M;
}
printf("%lld\n", a[n/2]);
}
return 0;
}
/**************************************************************
Problem: 1547
User: liangrx06
Language: C
Result: Accepted
Time:50 ms
Memory:912 kb
****************************************************************/
1548
#include <stdio.h>
#define N 100
int main(void)
{
int n, i, j, k;
int a[N][2];
while (scanf("%d", &n) != EOF)
{
for (i=0; i<n; i++)
scanf("%d%d", &a[i][0], &a[i][1]);
int max = 0;
for (i=0; i<n; i++)
{
for (j=i+1; j<n; j++)
{
int num = 2;
while(j<n && a[i][0] == a[j][0] && a[i][1] == a[j][1])
{
j ++;
num ++;
}
if (j == n)
num --;
for (k=j+1; k<n; k++)
{
if (k == i)
{
k = j;
continue;
}
if ( (a[i][0]-a[j][0])*(a[i][1]-a[k][1])
== (a[i][0]-a[k][0])*(a[i][1]-a[j][1]) )
num ++;
}
max = num>max ? num : max;
}
}
printf("%d\n", max);
}
return 0;
}
/************************************************************** Problem: 1548 User: liangrx06 Language: C Result: Accepted Time:40 ms Memory:912 kb ****************************************************************/
1549
int main()
{
int n;
int count;
while(scanf("%d", &n) != EOF)
{
count = 0;
count += n/100;
if (n%100 == 0)
{
printf("%d\n", count); continue;
}
n %= 100;
count += n/50;
if (n%50 == 0)
{
printf("%d\n", count); continue;
}
n %= 50;
count += n/20;
if (n%20 == 0)
{
printf("%d\n", count); continue;
}
n %= 20;
count += n/10;
if (n%10 == 0)
{
printf("%d\n", count); continue;
}
n %= 10;
count += n/5;
if (n%5 == 0)
{
printf("%d\n", count); continue;
}
n %= 5;
count += n/2;
if (n%2 == 0)
{
printf("%d\n", count); continue;
}
n %= 2;
count += 1;
printf("%d\n", count);
}
return 0;
}
/**************************************************************
Problem: 1549
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/
1550
#include <stdio.h>
#define M 100000
int main()
{
int i, n;
int a[M], b[M];
while(scanf("%d", &n) != EOF && n)
{
for (i=0; i<n; i++)
scanf("%d", &b[i]);
a[0] = 1;
for (i=1; i<n; i++)
{
a[i] = 1;
if (b[i] > b[i-1])
a[i] = a[i-1]+1;
}
int sum = a[n-1];
for (i=n-2; i>=0; i--)
{
if (b[i] > b[i+1] && a[i] <= a[i+1])
a[i] = a[i+1]+1;
sum += a[i];
}
printf("%d\n", sum);
}
return 0;
}
/************************************************************** Problem: 1550 User: liangrx06 Language: C Result: Accepted Time:70 ms Memory:1624 kb ****************************************************************/