11:00~11:30 背单词
今天睡的太死了,闹钟都叫不醒我,醒来一看手机发现已经十点了,唉
14:00~16:00 看csdn
19:00~21:30 测试
本来还想把下午的时间用来刷题,没想到测试提前了,刷了两个题的我有点菜菜的。
You are given two integers n and k.
You should create an array of n positive integers a1,a2,…,an such that the sum (a1+a2+⋯+an) is divisible by k and maximum element in a is minimum possible.
What is the minimum possible maximum element in a?
Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases.
The first and only line of each test case contains two integers n and k (1≤n≤109; 1≤k≤109).
Output
For each test case, print one integer — the minimum possible maximum element in array a such that the sum (a1+⋯+an) is divisible by k.
Example
Input
4
1 5
4 3
8 8
8 17
Output
5
2
1
3
Note
In the first test case n=1, so the array consists of one element a1 and if we make a1=5 it will be divisible by k=5 and the minimum possible.
In the second test case, we can create array a=[1,2,1,2]. The sum is divisible by k=3 and the maximum is equal to 2.
In the third test case, we can create array a=[1,1,1,1,1,1,1,1]. The sum is divisible by k=8 and the maximum is equal to 1.
这道题是个签到题,直接上代码吧。
#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
long long n,k,a,b=0;
scanf("%lld%lld",&n,&k);
if(n>k)
{
if(n%k!=0) a=n/k+1;
else a=n/k;
k*=a;
}
a=k/n;
if(k>a*n) b++;
printf("%lld\n",a+b);
}
}
Nezzar has n balls, numbered with integers 1,2,…,n. Numbers a1,a2,…,an are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that ai≤ai+1 for all 1≤i<n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.
Note that a sequence with the length at most 1 is considered as a strictly increasing sequence.
Please help Nezzar determine the minimum number of colors.
Input
The first line contains a single integer t (1≤t≤100) — the number of testcases.
The first line of each test case contains a single integer n (1≤n≤100).
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n). It is guaranteed that a1≤a2≤…≤an.
Output
For each test case, output the minimum number of colors Nezzar can use.
Example
Input
5
6
1 1 1 2 3 4
5
1 1 2 2 3
4
2 2 2 2
3
1 2 3
1
1
Output
3
2
4
1
1
这道题其实我题目没怎么看明白,但是样例很清楚,也是个难度不高的题
#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,a[1010],max=0,x=1,i=0;
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%d",&a[i]);
for(i=0; i<n; i++)
{
//printf("%d\n",a[i]);
if(i!=0)
{
//printf("x=%d\n",x);
if(a[i]==a[i-1])
x++;
else
{
max=(max>x)?max:x;
x=1;
}
}
}
max=(max>x)?max:x;
printf("%d\n",max);
}
}
21:30~23:30 刷题
问题 B: 二叉树,知中序后序,求先序(递归)
描述
已知二叉树的中序、后序,建树求先序。
格式
输入格式
中序序列
后序序列
输出格式
先序序列
样例
样例输入 Copy
d g b a e c f
g d b e f c a
样例输出 Copy
a b d g c e f
今天一直卡在这道题上,唉。后面发现是输入的问题,卡在这里真不值
代码:
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct TREE)
struct TREE
{
char data;
struct TREE *l,*r;
};
typedef struct TREE A;
A * fun1(char ch1[],char ch2[],int n)
{
A *p;
if(n==0)
{
p=NULL;
}
else
{
int i=0,n1,n2;
char x=ch2[n-1];
A *q1,*q2;
p=(A *)malloc(LEN);
p->data=x;
for(i=0; i<n; i++)
if(ch1[i]==x)
break;
n1=i,n2=n-n1-1;
//printf("n1=%d n2=%d\n",n1,n2);
q1=fun1(ch1,ch2,n1);
q2=fun1(ch1+i+1,ch2+n1,n2);
p->l=q1,p->r=q2;
}
return p;
}
void fun2(A * p)
{
if(p!=NULL)
{
printf("%c ",p->data);
fun2(p->l);
fun2(p->r);
free(p);
}
}
int main()
{
char ch[1010];
int n=0;
while(scanf("%s",&ch[n++])!=EOF);
//printf("%s",ch);
A *root;
root=fun1(ch,ch+n/2,n/2);
fun2(root);
}
总计学习7小时。
测试完人都不好了,今天早点睡,明天早点起,拜拜。