1531
#include <stdio.h>
#include <stdlib.h>
#define N 100
int cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int main(void)
{
int n, i;
int a[N], sum[N];
while (scanf("%d", &n) != EOF)
{
for(i=0; i<n; i++)
scanf("%d", &a[i]);
qsort(a, n, sizeof(a[0]), cmp);
if (a[0] != 1)
{
printf("1\n");
continue;
}
sum[0] = a[0];
for (i=1; i<n; i++)
{
if (a[i] > sum[i-1]+1)
{
printf("%d\n", sum[i-1]+1);
break;
}
sum[i] = sum[i-1]+a[i];
}
if (i == n)
printf("%d\n", sum[n-1]+1);
}
return 0;
}
1532
#include <stdio.h>
#include <string.h>
#define N 8
#define SINGLE 100
#define M 1000
int n;
int islegal(int i, int j)
{
return i>=0 && i<n && j>=0 && j<n;
}
int main(void)
{
int i, j, k, limit, min;
int a[N][N], b[N][N], c[N][N][M+1];
n = N;
while (scanf("%d", &limit) != EOF)
{
for(i=0; i<n; i++)
{
for (j=0; j<n; j++)
{
scanf("%d", &a[i][j]);
}
}
memset(c, 0, sizeof(c));
for(i=0; i<n; i++)
{
for (j=0; j<n; j++)
{
if (!i && !j)
{
b[0][0] = a[0][0];
c[0][0][a[0][0]] = 1;
continue;
}
int max = 0;
if (islegal(i-1, j))
max = (b[i-1][j] > max) ? b[i-1][j] : max;
if (islegal(i, j-1))
max = (b[i][j-1] > max) ? b[i][j-1] : max;
b[i][j] = a[i][j]+max;
min = (limit < b[i][j]) ? limit : b[i][j];
for (k=a[i][j]; k<=min; k++)
{
if (islegal(i-1, j) && c[i-1][j][k-a[i][j]])
c[i][j][k] = 1;
if (islegal(i, j-1) && c[i][j-1][k-a[i][j]])
c[i][j][k] = 1;
}
}
}
for (k=min; k>=a[n-1][n-1]; k--)
{
if (c[n-1][n-1][k])
break;
}
if (k < a[n-1][n-1])
printf("%d\n", -1);
else
printf("%d\n", k);
}
return 0;
}
1533
#include <stdio.h>
#define N 100000
void print(int x[N], int c)
{
for (int i=0; i<c; i++)
printf("%d ", x[i]);
printf("\n");
}
int binSearch(int big[], int begin, int end, int k)
{
if (end == -1)
return -1;
if (begin == end)
{
if (big[begin] < k)
return begin;
else
return -1;
}
int mid = (begin+end)/2;
if (big[mid+1] >= k)
return binSearch(big, begin, mid, k);
else
return binSearch(big, mid+1, end, k);
}
int insert(int big[], int count, int k)
{
int j;
j = binSearch(big, 0, count-1, k);
if (j == count-1 || big[j+1] > k)
{
big[j+1] = k;
if (j == count-1)
count ++;
}
return count;
}
int main(void)
{
int a[N], n, i;
int big[N], count;
while (scanf("%d", &n) != EOF)
{
for(i=0; i<n; i++)
scanf("%d", &a[i]);
count = 0;
for(i=0; i<n; i++)
count = insert(big, count, a[i]);
printf("%d\n", count);
}
return 0;
}
1534
#include <stdio.h>
#include <stdlib.h>
#define N 100000
long long m, n;
long long a[N], b[N];
long long rank(long long mid)
{
long long i, j;
long long cnt = 0;
j = n-1;
for (i=0; i<m; i++)
{
while (j >= 0 && a[i]+b[j] > mid)
j--;
cnt += (j+1);
}
return cnt;
}
int cmp(const void *a, const void *b)
{
return *(long long *)a - *(long long *)b;
}
int main(void)
{
long long k, i;
while (scanf("%lld%lld%lld", &m, &n, &k) != EOF)
{
for(i=0; i<m; i++)
scanf("%lld", &a[i]);
for(i=0; i<n; i++)
scanf("%lld", &b[i]);
qsort(a, m, sizeof(a[0]), cmp);
qsort(b, n, sizeof(b[0]), cmp);
long long min = a[0] + b[0];
long long max = a[m-1] + b[n-1];
while(min <= max)
{
long long mid = (min+max)/2;
if (rank(mid) >= k)
max = mid-1;
else
min = mid+1;
}
printf("%lld\n", min);
}
return 0;
}
1535
int main(void)
{
int na, nb, i, ia, ib;
char a[N+1], b[N+1];
int max;
while (scanf("%s%s", a, b) != EOF)
{
na = strlen(a);
nb = strlen(b);
max = 0;
i = (na>nb) ? (na-nb) : 0;
while (i < na)
{
if (a[i] == b[0])
{
ia = i;
ib = 0;
while (a[ia] == b[ib] && ia < na)
{
ia ++;
ib ++;
}
if (ia == na)
{
max = (ib > max) ? ib : max;
break;
}
}
i ++;
}
printf("%d\n", max);
}
return 0;
}
/**************************************************************
Problem: 1535
User: liangrx06
Language: C
Result: Accepted
Time:200 ms
Memory:2792 kb
****************************************************************/
1536(未完成)
1537
int main()
{
int n, k, i, j;
int w[N+1];
int dp[N+1][N+1];
while(scanf("%d%d", &n, &k) != EOF)
{
for(i=1; i<=n; i++)
scanf("%d", &w[i]);
memset(dp, 0, sizeof(dp));
for(i=1; i<=k; i++)
{
int max = dp[i-1][1] - w[1];
for(j=2; j<=n; j++)
{
max = (dp[i-1][j-1] - w[j-1]) > max ? (dp[i-1][j-1] - w[j-1]) : max;
dp[i][j] = ((max + w[j]) > dp[i][j-1]) ? (max + w[j]) : dp[i][j-1];
}
}
printf("%d\n", dp[k][n]);
}
return 0;
}
/**************************************************************
Problem: 1537
User: liangrx06
Language: C
Result: Accepted
Time:70 ms
Memory:4760 kb
****************************************************************/
1538
int main(void)
{
int i;
char s[N+1];
int trans[] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5,
6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9};
while (scanf("%s", s) != EOF)
{
for(i=0; s[i]; i++)
printf("%d", trans[s[i]-'a']);
printf("\n");
}
return 0;
}
/**************************************************************
Problem: 1538
User: liangrx06
Language: C
Result: Accepted
Time:50 ms
Memory:912 kb
****************************************************************/
1539(未完成)
1540(未完成)