This commit is contained in:
Saturneric 2020-09-01 00:48:58 +08:00
parent c5dd2cf9b5
commit 0525ffad24
374 changed files with 2372 additions and 0 deletions

93
1166/main.c Normal file
View File

@ -0,0 +1,93 @@
#include <stdio.h>
struct node {
long from, to;
unsigned long long value;
};
int build_tree(struct node *tree,int *stations, long idx, int from, int to);
unsigned long long find_section(struct node *tree, long idx, int from, int to);
int add_point(struct node * tree, long idx, int p_idx, int value);
int sub_point(struct node * tree, long idx, int p_idx, int value);
int stations[50000];
struct node tree[200000];
int main(void) {
int no;
scanf("%d",&no);
int k,i;
for(k = 0; k < no; k++){
printf("Case %d:\n",k+1);
int n;
scanf("%d",&n);
for(i = 0; i < n; i++){
scanf("%d",&stations[i]);
}
build_tree(tree, stations, 0, 1, n);
char order[6];
while(scanf("%s",order) && order[0]!='E'){
if(order[0]=='A'){
int idx, peo;
scanf("%d %d",&idx,&peo);
add_point(tree, 0, idx, peo);
}
else if(order[0]=='S'){
int idx, peo;
scanf("%d %d",&idx,&peo);
sub_point(tree, 0, idx, peo);
}
else if(order[0]=='Q'){
int idxa, idxb;
scanf("%d %d",&idxa,&idxb);
printf("%llu\n",find_section(tree, 0, idxa, idxb));
}
}
}
return 0;
}
int build_tree(struct node *tree,int *stations, long idx, int from, int to){
tree[idx].from = from;
tree[idx].to = to;
if(from - to){
build_tree(tree, stations, 2*idx+1, from, (from+to)/2);
build_tree(tree, stations, 2*idx+2, (from+to)/2+1, to);
tree[idx].value = tree[2*idx+1].value + tree[2*idx+2].value;
}
else tree[idx].value = stations[from-1];
return 0;
}
unsigned long long find_section(struct node *tree, long idx, int from, int to){
long h_idx = (tree[idx].from + tree[idx].to)/2;
unsigned long long sum = 0;
if(tree[idx].from == from && tree[idx].to == to) return tree[idx].value;
else if(from <= h_idx && to > h_idx)
sum += find_section(tree, 2*idx+1, from, h_idx) + find_section(tree, 2*idx+2, h_idx+1, to);
else if(from <= h_idx && to <= h_idx) sum += find_section(tree,2*idx+1, from, to);
else if (from > h_idx && to > h_idx) sum += find_section(tree,2*idx+2, from, to);
return sum;
}
int add_point(struct node * tree, long idx, int p_idx, int value){
long h_idx = (tree[idx].from+tree[idx].to)/2;
tree[idx].value += value;
if(tree[idx].from < tree[idx].to){
if(p_idx <= h_idx) add_point(tree, idx*2+1, p_idx, value);
else add_point(tree, idx*2+2, p_idx, value);
}
return 0;
}
int sub_point(struct node * tree, long idx, int p_idx, int value){
long h_idx = (tree[idx].from+tree[idx].to)/2;
tree[idx].value -= value;
if(tree[idx].from < tree[idx].to){
if(p_idx <= h_idx) sub_point(tree, idx*2+1, p_idx, value);
else sub_point(tree, idx*2+2, p_idx, value);
}
return 0;
}

0
1166/problem.set Normal file
View File

0
1166/stdin Normal file
View File

0
1166/stdout Normal file
View File

74
1754/main.c Normal file
View File

@ -0,0 +1,74 @@
#include <stdio.h>
struct node {
long from, to;
long value;
};
int build_tree(struct node *tree,int *stations, long idx, long from, long to);
long find_section(struct node *tree, long idx, long from, long to);
int upd_point(struct node * tree, long idx, long p_idx, long value);
#define MAX (200000+5)
int students[MAX];
struct node tree[4*MAX];
int main(void) {
long sn, cn, i;
while(scanf("%ld %ld",&sn,&cn) != EOF){
for(i = 0; i < sn; i++) scanf("%d",students+i);
build_tree(tree, students, 0, 1, sn);
for(i = 0; i < cn; i++){
char cmd[2];
scanf("%s",cmd);
if(cmd[0] == 'Q'){
long fidx, tidx;
scanf("%ld %ld",&fidx,&tidx);
printf("%ld\n",find_section(tree, 0,fidx, tidx));
}
else if(cmd[0] == 'U'){
long idx;
int value;
scanf("%ld %d",&idx,&value);
upd_point(tree, 0, idx, value);
}
}
}
return 0;
}
int build_tree(struct node *tree,int *students, long idx, long from, long to){
tree[idx].from = from;
tree[idx].to = to;
if(from < to){
build_tree(tree, students, 2*idx+1, from, (from+to)/2);
build_tree(tree, students, 2*idx+2, (from+to)/2+1, to);
tree[idx].value = (tree[2*idx+1].value)>(tree[2*idx+2].value)?(tree[2*idx+1].value):(tree[2*idx+2].value);
}
else tree[idx].value = students[from-1];
return 0;
}
long find_section(struct node *tree, long idx, long from, long to){
long h_idx = (tree[idx].from + tree[idx].to)/2;
if(tree[idx].from == from && tree[idx].to == to)
return tree[idx].value;
if(from <= h_idx && to > h_idx){
long f = find_section(tree, idx*2+1, from, h_idx), s = find_section(tree, idx*2+2, h_idx+1, to);
return f>s?f:s;
}
else if(from <= h_idx && to <= h_idx) return find_section(tree, idx*2+1, from, to);
else if(from > h_idx && to > h_idx) return find_section(tree, idx*2+2, from, to);
else return 0;
}
int upd_point(struct node * tree, long idx, long p_idx, long value){
long h_idx = (tree[idx].from+tree[idx].to)/2;
if(tree[idx].from < tree[idx].to){
if(p_idx <= h_idx) upd_point(tree, idx*2+1, p_idx, value);
else upd_point(tree, idx*2+2, p_idx, value);
}
if(tree[idx].value < value) tree[idx].value = value;
return 0;
}

0
1754/problem.set Normal file
View File

0
1754/stdin Normal file
View File

0
1754/stdout Normal file
View File

22
2000/main.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdio.h>
int main(void){
char input[3] = {'\0'},temp = '\0';
while(scanf("%c%c%c",&input[0],&input[1],&input[2]) == 3){
int if_cge = 1,i = 0;
while(if_cge){
if_cge = 0;
for(i = 0; i<2; i++){
if(input[i] > input[i+1]){
temp = input[i+1];
input[i+1] = input[i];
input[i] = temp;
if_cge = 1;
}
}
}
printf("%c %c %c\n",input[0],input[1],input[2]);
getchar();
}
return 0;
}

BIN
2000/problem.build Normal file

Binary file not shown.

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.problem.build</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

0
2000/problem.set Normal file
View File

3
2000/stdin Normal file
View File

@ -0,0 +1,3 @@
qwe
asd
zxc

3
2000/stdout Normal file
View File

@ -0,0 +1,3 @@
e q w
a d s
c x z

12
2001/main.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include <math.h>
#define TWOQ(x) ((x)*(x))
int main(void){
double x1,x2,y1,y2;
while(scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2) == 4){
printf("%.2lf\n",sqrt(TWOQ(x1-x2)+TWOQ(y1-y2)));
getchar();
}
return 0;
}

BIN
2001/problem.build Normal file

Binary file not shown.

0
2001/problem.set Normal file
View File

2
2001/stdin Normal file
View File

@ -0,0 +1,2 @@
0 0 0 1
0 1 1 0

2
2001/stdout Normal file
View File

@ -0,0 +1,2 @@
1.00
1.41

12
2002/main.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
#define PI 3.1415927
#define TQ(x) ((x)*(x)*(x))
int main(void){
double r = 0.0;
while(scanf("%lf",&r) == 1){
printf("%.3lf\n",(4.0/3.0)*PI*TQ(r));
getchar();
}
return 0;
}

BIN
2002/problem.build Normal file

Binary file not shown.

0
2002/problem.set Normal file
View File

6
2002/stdin Normal file
View File

@ -0,0 +1,6 @@
1
1.5
1.25
2.4
3.6
65535

6
2002/stdout Normal file
View File

@ -0,0 +1,6 @@
4.189
14.137
8.181
57.906
195.432
1178985671427752.500

10
2003/main.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
int main(void){
double a = 0.0;
while(scanf("%lf",&a) == 1){
printf("%.2lf\n",a>0?a:-a);
getchar();
}
return 0;
}

BIN
2003/problem.build Normal file

Binary file not shown.

0
2003/problem.set Normal file
View File

2
2003/stdin Normal file
View File

@ -0,0 +1,2 @@
123
-234.00

2
2003/stdout Normal file
View File

@ -0,0 +1,2 @@
123.00
234.00

16
2004/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
int main(void){
int score = 0;
while(scanf("%d",&score) == 1){
if(score >= 0 && score <= 100)
if(score >= 90) printf("A\n");
else if(score >= 80) printf("B\n");
else if(score >= 70) printf("C\n");
else if(score >= 60) printf("D\n");
else printf("E\n");
else printf("Score is error!\n");
getchar();
}
return 0;
}

BIN
2004/problem.build Normal file

Binary file not shown.

0
2004/problem.set Normal file
View File

0
2004/std Normal file
View File

1
2004/stdin Normal file
View File

@ -0,0 +1 @@
2

1
2004/stdout Normal file
View File

@ -0,0 +1 @@
1.41421

24
2005/main.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main(void){
int year = 0, month = 0, day = 0;
int days = 0, i = 0;
while(scanf("%d/%d/%d",&year,&month,&day) == 3){
days = 0;
for(i = 0; i < month-1; i++){
days += months[i];
if(i == 1 && !(year % 4)){
if(!(year % 100)){
if(!(year % 400)) days++;
}
else days++;
}
}
days += day;
printf("%d\n",days);
getchar();
}
return 0;
}

BIN
2005/problem.build Normal file

Binary file not shown.

0
2005/problem.set Normal file
View File

4
2005/stdin Normal file
View File

@ -0,0 +1,4 @@
1985/1/20
2006/3/12
2004/12/31
2000/12/31

4
2005/stdout Normal file
View File

@ -0,0 +1,4 @@
20
71
366
366

16
2006/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
int main(void){
int numbers = 0;
while(scanf("%d",&numbers) == 1){
int temp = 0, all = 1;
while(temp++ < numbers){
int n = 0;
scanf("%d",&n);
if(n % 2) all *= n;
}
printf("%d\n",all);
getchar();
}
return 0;
}

BIN
2006/problem.build Normal file

Binary file not shown.

0
2006/problem.set Normal file
View File

2
2006/stdin Normal file
View File

@ -0,0 +1,2 @@
3 1 2 3
4 2 3 4 5

2
2006/stdout Normal file
View File

@ -0,0 +1,2 @@
3
15

23
2007/main.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
#define TWQ(x) ((x)*(x))
#define THQ(x) ((x)*(x)*(x))
#define ABS(x) ((x)>0?(x):(-(x)))
int main(void){
int m = 0, n = 0;
while(scanf("%d %d",&m,&n) == 2){
long o = 0,j = 0;
int i = 0;
if(m > n){
i = m;
m = n;
n = i;
}
for(i = m ; i <= n; i++)
if(ABS(i) % 2) j += THQ(i);
else o += TWQ(i);
printf("%ld %ld\n",o,j);
getchar();
}
return 0;
}

BIN
2007/problem.build Normal file

Binary file not shown.

0
2007/problem.set Normal file
View File

4
2007/stdin Normal file
View File

@ -0,0 +1,4 @@
1 3
2 5
1 100
-5 3

4
2007/stdout Normal file
View File

@ -0,0 +1,4 @@
4 28
20 152
171700 12497500
24 -125

19
2008/main.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
int main(void){
int numbers = 0;
while(scanf("%d",&numbers) == 1){
if(!numbers) continue;
int temp = 0, a = 0, b = 0, c = 0;
double input = 0;
while(temp++ < numbers){
scanf("%lf",&input);
if(input < 0) a += 1;
else if(input == 0) b += 1;
else c += 1;
}
printf("%d %d %d\n",a,b,c);
getchar();
}
return 0;
}

BIN
2008/problem.build Normal file

Binary file not shown.

0
2008/problem.set Normal file
View File

3
2008/stdin Normal file
View File

@ -0,0 +1,3 @@
6 0 1 2 3 -1 0
5 1 2 3 4 0.5
0

2
2008/stdout Normal file
View File

@ -0,0 +1,2 @@
1 2 3
0 0 5

16
2009/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <math.h>
int main(void){
int n = 0, m = 0;
while(scanf("%d %d",&n,&m) == 2){
int i = 0;
double all = 0.0, temp = n;
for(i = 0; i < m; i++){
all += temp;
temp = sqrt(temp);
}
printf("%.2lf\n",all);
getchar();
}
return 0;
}

BIN
2009/problem.build Normal file

Binary file not shown.

0
2009/problem.set Normal file
View File

2
2009/stdin Normal file
View File

@ -0,0 +1,2 @@
81 4
2 2

2
2009/stdout Normal file
View File

@ -0,0 +1,2 @@
94.73
3.41

25
2010/main.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#define THQ(x) ((x)*(x)*(x))
int main(void){
int m = 0, n = 0;
while(scanf("%d %d",&m,&n) == 2){
int i = 0, tar[3], j = 0, count = 0, temp = 0;
for(i = m; i <= n; i++){
temp = i;
for(j = 0; j < 3; j++){
tar[j] = temp%10;
temp /= 10;
}
if(i == THQ(tar[0]) + THQ(tar[1]) + THQ(tar[2])){
if(count) printf(" ");
printf("%d",i);
count++;
}
}
if(!count) printf("no\n");
else printf("\n");
getchar();
}
return 0;
}

BIN
2010/problem.build Normal file

Binary file not shown.

0
2010/problem.set Normal file
View File

2
2010/stdin Normal file
View File

@ -0,0 +1,2 @@
100 120
300 380

2
2010/stdout Normal file
View File

@ -0,0 +1,2 @@
no
370 371

18
2011/main.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
int main(void){
int numbers = 0;
scanf("%d",&numbers);
int count = 0, m = 0;
while(count++ < numbers){
scanf("%d",&m);
int i = 0;
double all = 1.0;
for(i = 2 ; i <= m; i++){
if(!(i % 2)) all -= 1.0/i;
else all += 1.0/i;
}
printf("%.2lf\n",all);
}
return 0;
}

BIN
2011/problem.build Normal file

Binary file not shown.

0
2011/problem.set Normal file
View File

2
2011/stdin Normal file
View File

@ -0,0 +1,2 @@
3
1 2 3

3
2011/stdout Normal file
View File

@ -0,0 +1,3 @@
1.00
0.50
0.83

29
2012/main.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <math.h>
int main(void){
int x = 0, y = 0;
while(scanf("%d %d",&x,&y) == 2){
int i = 0, temp = 0, j = 0, if_ass = 1;
if(!x && !y) continue;
for(i = x; i <= y; i++){
int if_ss = 1;
temp = i * i + i + 41;
if(!(temp % 2)) if_ss = 0;
else for(j = 2 ; j <= sqrt(temp); j++){
if(!(temp % j)){
if_ss = 0;
break;
}
}
if(!if_ss){
printf("Sorry\n");
if_ass = 0;
break;
}
}
if(if_ass) printf("OK\n");
getchar();
}
return 0;
}

BIN
2012/problem.build Normal file

Binary file not shown.

0
2012/problem.set Normal file
View File

3
2012/stdin Normal file
View File

@ -0,0 +1,3 @@
0 1
0 0
-39 12

2
2012/stdout Normal file
View File

@ -0,0 +1,2 @@
OK
OK

15
2013/main.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main(void){
int days = 0;
while(scanf("%d",&days) == 1){
int i = 0, numbers = 1;
for(i = 1; i < days; i++){
numbers += 1;
numbers *= 2;
}
printf("%d\n",numbers);
getchar();
}
return 0;
}

BIN
2013/problem.build Normal file

Binary file not shown.

0
2013/problem.set Normal file
View File

2
2013/stdin Normal file
View File

@ -0,0 +1,2 @@
2
4

2
2013/stdout Normal file
View File

@ -0,0 +1,2 @@
4
22

26
2014/main.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
int main(void){
int numbers = 0;
while(scanf("%d",&numbers) == 1){
int count = 0, temp[120] = {0}, max = 0, min = 0;
double avg = 0.0;
while(count < numbers){
scanf("%d",&temp[count]);
if(!count){
max = temp[count];
min = temp[count];
}
else{
if(max < temp[count]) max = temp[count];
if(min > temp[count]) min = temp[count];
}
count++;
}
for(count = 0; count < numbers; count++)
if(temp[count] != max && temp[count] != min) avg += (double)temp[count] / (double)(numbers-2);
printf("%.2lf\n",avg);
getchar();
}
return 0;
}

BIN
2014/problem.build Normal file

Binary file not shown.

0
2014/problem.set Normal file
View File

3
2014/stdin Normal file
View File

@ -0,0 +1,3 @@
3 99 98 97
4 100 99 98 97
10 100 56 78 34 24 23 45 14 12 23

3
2014/stdout Normal file
View File

@ -0,0 +1,3 @@
98.00
98.50
37.12

31
2015/main.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
int main(void){
int n = 0, m = 0;
while(scanf("%d %d",&n,&m) == 2){
int i = 0, number = 2, count = 1, all = 0, if_print = 0;
for(i = 0; i < n; i++){
all += number;
count++;
if(count > m){
if(if_print) printf(" ");
all /= --count;
printf("%d",all);
all = 0;
count = 1;
if_print = 1;
}
number += 2;
}
if(count > 1)
all /= --count;
else all = 0;
if(all != 0) {
if(if_print) printf(" ");
printf("%d",all);
}
printf("\n");
getchar();
}
return 0;
}

BIN
2015/problem.build Normal file

Binary file not shown.

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.problem.build</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

0
2015/problem.set Normal file
View File

2
2015/stdin Normal file
View File

@ -0,0 +1,2 @@
3 2
4 2

2
2015/stdout Normal file
View File

@ -0,0 +1,2 @@
3 6
3 7

27
2016/main.c Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
int main(void){
int numbers = 1, ac[100] = {};
while(scanf("%d",&numbers) == 1){
if(!numbers) continue;
int i = 0, min = 0, temp = 0, index = 0;
for(i = 0; i < numbers; i++){
scanf("%d",&ac[i]);
if(!i) min = ac[i];
else if(min > ac[i]){
min = ac[i];
index = i;
}
}
temp = ac[0];
ac[0] = min;
ac[index] = temp;
for(i = 0; i < numbers; i++){
if(i) printf(" ");
printf("%d",ac[i]);
}
printf("\n");
getchar();
}
return 0;
}

BIN
2016/problem.build Normal file

Binary file not shown.

0
2016/problem.set Normal file
View File

2
2016/stdin Normal file
View File

@ -0,0 +1,2 @@
4 2 1 3 4
5 5 4 3 2 1

2
2016/stdout Normal file
View File

@ -0,0 +1,2 @@
1 2 3 4
1 4 3 2 5

18
2017/main.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
int main(void){
long numbers = 0;
scanf("%ld",&numbers);
long i = 0;
char string[1024];
for(i = 0; i < numbers; i++){
scanf("%s",string);
long count = 0, temp = 0;
while(string[count] != '\0'){
if(string[count] > 47 && string[count] < 58) temp++;
count++;
}
printf("%ld\n",temp);
}
return 0;
}

BIN
2017/problem.build Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More