数据范围,emmm,果断字符串做

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <string.h>
#define scan(x) scanf("%d", &x)

int main()
{
char s[10000];
int a, x;
scan(a);
while (a--)
{
scanf("%s", s);
x = s[strlen(s) - 1] - '0';
if (x & 1)
printf("odd\n");
else
printf("even\n");
}
return 0;
}

打卡题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int getMaximumGenerated(int n){
if(n<2)
return n==0?0:1;
int max=0;
int *nums=(int *)malloc(sizeof(int)*(n+1));
nums[0]=0;nums[1]=1;
for(int j=2;j<=n;j++){
if(j&1)
nums[j]=nums[j/2]+nums[j/2+1];
else nums[j]=nums[j/2];
max=max<nums[j]?nums[j]:max;
}
return max;
}

笑了,返回字符串数组末尾加上’\0’会报

AddressSanitizer: heap-buffer-overflow on address

开两个数组,一个记录字符,一个记录个数,mark标记上一字符,若不同则更新mark

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#define f(i, a, b) for (int i = a; i <= b; i++)

int compress(char* chars, int charsSize){
int a[2000]={0},b[2000]={0},ac=0;
char mark='\0';
f(i,0,charsSize-1){
if(chars[i]!=mark){
a[ac]=chars[i];
b[ac++]=1;
mark=chars[i];
}
else if(chars[i]==mark){
b[ac-1]+=1;
}
}
int now=0;
f(j,0,ac-1){
if(b[j]==1)
chars[now++]=a[j];
else {
chars[now++]=a[j];
char temp[10];
sprintf(temp,"%d",b[j]);
f(k,0,strlen(temp)-1)
chars [now++]=temp[k];
}
}
return now;
}

先check是不是完全满足,不是再二分订单查找不满足的订单

一开始写得像个弱智一样,check函数最后累加时for循坏竟写成

1
2
3
4
5
6
7
...
#define f(i, a, b) for (int i = a; i <= b; i++)
...
int check(int md){
f(i, 1, md)
...
}

而实际上边界值应该是n

阅读全文 »

今天在群里看到了这个题问题然后群里的康老师给了解答解答

忽然想起了那段时光,可惜最后还是成了一个遗憾,中高考数学竟然一样的分111,唉~

《导数的秘密》看了千百遍,放缩取点练了无数次,没想到最后败在极值点。相交弦定理没看出来,双曲线看错题,抛物线也看错写成抛物线方程,倒是最后的语文还算行,不知后事如何了!

0%