Thank you to 冰封 !

This commit is contained in:
unknown 2016-07-06 14:28:18 +08:00
parent 4a01c864b1
commit a6239fc1fd
59 changed files with 2027 additions and 0 deletions

5
CodeVS/1000_冰封.pas Normal file
View File

@ -0,0 +1,5 @@
var a, b:longint;
begin
readln(a,b);
writeln(a+b);
end.

86
CodeVS/1001_冰封.cpp Normal file
View File

@ -0,0 +1,86 @@
#include <stdio.h>
const int BIG = 0x3f3f3f3f;
const int size = 501;
int N, min = BIG, max = -BIG, to;
int a[size][size];
bool used[size];
int save[size][2];
int save_cnt;
void dfs(int c);
int get();
void test();
int main(int argc, char* argv[]){
auto int M;
auto int x, y, v;
auto int fr;
// test();
scanf("%i%i", &N, &M);
for(auto int i = 0; i < M; i++){
scanf("%i%i%i", &x, &y, &v);
a[x][y] = v;
}
scanf("%i%i", &fr, &to);
used[fr] = true;
dfs(fr);
if(!save_cnt)
printf("IMPOSSIBLE");
else {
int cur = 0;
for(auto int i = 0; i < save_cnt; i++){
int q = save[i][1] / save[i][0];
if(q < save[cur][1] / save[cur][0])
cur = q;
// printf("save[%i][1] = %i, save[%i][0] = %i\n",i , save[i][1],i , save[i][0]);
}
max = save[cur][1];
min = save[cur][0];
get();
if(min == 1)
printf("%i", max);
else
printf("%i/%i", max, min);
}
return 0;
}
void dfs(int c) {
if(c == to) {
// printf("arrived.\n");
save[save_cnt][0] = min;
save[save_cnt][1] = max;
save_cnt++;
min = -BIG;
max = BIG;
return ;
}
for(auto int i = 0; i <= N; i++) {
if(a[c][i] && !used[i]) {
if(a[c][i] > max) max = a[c][i];
if(a[c][i] < min) min = a[c][i];
used[i] = true;
// printf("from %i to %i\n", c, i);
dfs(i);
used[i] = false;
}
}
}
int get(){
for(auto int i = 2; i <= max; i++){
if(min % i == 0 && max % i == 0){
min /= i;
max /= i;
i--;
}
}
}
void test(){
max = 6;
min = 3;
get();
printf("6 / 3 => %i / %i\n", max, min);
}

20
CodeVS/1007_冰封.c Normal file
View File

@ -0,0 +1,20 @@
/*
:
:p1007
float了
*/
#include <stdio.h>
int main(){
int a, i;
double b = 0.0;
scanf("%i", &a);
for(i = 1; b < a; i++){
b += 1.0 / i;
if(b >= a)
break;
}
printf("%i", i);
return 0;
}

39
CodeVS/1010_冰封.c Normal file
View File

@ -0,0 +1,39 @@
#include <stdio.h>
int xx, yy, hx, hy;
int cnt;
int a[1000][1000];
void dfs(int x, int y);
int main(int argc, char* argv[]){
scanf("%i%i%i%i", &xx, &yy, &hx, &hy);
a[hx][hy] = 1;
a[hx + 1][hy + 2] = 1;
a[hx + 1][hy - 2] = 1;
a[hx - 1][hy + 2] = 1;
a[hx - 1][hy - 2] = 1;
a[hx + 2][hy + 1] = 1;
a[hx + 2][hy - 1] = 1;
a[hx - 2][hy - 1] = 1;
a[hx - 2][hy + 1] = 1;
dfs(0, 0);
printf("%i", cnt);
return 0;
}
void dfs(int x, int y){
if(x == xx || y == yy){
cnt++;
return ;
}
if(x < 0 || y < 0 || x >= xx || y >= yy || a[x][y] == 1){
return ;
}
a[x][y] = 1;
dfs(x + 1, y);
dfs(x, y + 1);
a[x][y] = 0;
}

20
CodeVS/1011_冰封.c Normal file
View File

@ -0,0 +1,20 @@
#include<stdio.h>
int res = 0;
void dfs(int cur){
if(cur == 0)
return ;
res++;
auto int i;
for(i = 1; i <= cur / 2; i++)
dfs(i);
}
int main(int argc, char* argv[]){
auto int num = 0;
scanf("%i", &num);
dfs(num);
printf("%i", res);
// while(1);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
:
:p1012
*/
#include <stdio.h>
long get(long x, long y){
long m = y / x;
long i, cnt = 0;
for(i = 1; i < m; i++){
}
}
int main(int argc, char* argv[]){
long a, b, m;
scanf("%i%i", &a, &b);
printf("%i", get(a, b));
return 0;
}

24
CodeVS/1014_冰封.c Normal file
View File

@ -0,0 +1,24 @@
/*
:
:p1014
*/
int i, v, max = 0, a[35], n;
#include<stdio.h>
#include<memory.h>
void dfs(int idx, int size){
if(size >= v) return ;
max = max > size ? max : size;
if(idx >= n - 1) return ;
idx++;
dfs(idx, size);
dfs(idx, size + a[idx]);
}
int main(){
scanf("%i%i", &v, &n);
for(i = 0; i < n; i++)
scanf("%i", &a[i]);
dfs(-1, 0);
printf("%i", v - max);
return 0;
}

19
CodeVS/1023_冰封.c Normal file
View File

@ -0,0 +1,19 @@
/*
:
:p1023 GPA计算
*/
#include <stdio.h>
int main(int argc, char* argv[]){
int a, i,c = 0, m = 0;
float n = 0.0, tol = 0.0;
scanf("%i", &a);
for(i = 0; i < a; i++){
scanf("%i%f", &m, &n);
tol += m * n;
c += m;
}
printf("%.2f", tol / c);
return 0;
}

View File

@ -0,0 +1,35 @@
/*
:
:p1025
*/
#include<stdio.h>
const int size = 101;
int k, n, d[size], c[size], m[size], dp[size];
double x, v[size];
int isin(int idx){
int i;
for(i= 0; i < k; i++)
if(idx == i) return 1;
return 0;
}
int main(){
scanf("%d%d%lf", &n, &k, &x);
int i;
for(i = 0; i < n; i++)
scanf("%d", &d[i]);
for(i = 0; i < n; i++)
scanf("%lf", &v[i]);
for(i = 0; i < n; i++)
scanf("%d", &c[i]);
for(i = 0; i < k; i++)
scanf("%d", &m[i]);
for(i = 0; i < n; i++){
int j;
for(j = n - 1; j >= v[i]; j++){
}
}
for(;;);
return 0;
}

49
CodeVS/1031_冰封.c Normal file
View File

@ -0,0 +1,49 @@
/*
:
:p1031
*/
#include <stdio.h>
#include <math.h>
int a[17];
int book[18];
int size;
int isPrime(int num){
int i;
for(i = 2; i <= sqrt(num); i++)
if(!(num % i))
return 0;
return 1;
}
void dfs(int idx){
if(idx == size){
if(!isPrime(a[0] + a[idx])) return ;
int i;
printf("1");
for(i = 1; i < size; i++)
printf(" %i", a[i]);
printf("\n");
return ;
}
int i;
for(i = 2; i <= size; i++){
if(!book[i] && isPrime(a[idx - 1] + i)){
book[i] = 1;
a[idx] = i;
dfs(idx + 1);
book[i] = 0;
}
}
}
int main() {
scanf("%i", &size);
a[0] = 1;
book[0] = 1;
book[1] = 1;
dfs(1);
return 0;
}

View File

@ -0,0 +1,37 @@
#include<stdio.h>
#include<memory.h>
const int size = 0xf;
int max(int x, int y){return x > y ? x : y;}
int main() {
int a[size][size], dp[size][size], n;
memset(a, 0, size * size);
memset(dp, 0, size * size);
scanf("%d", &n);
while(1){
int x, y, v;
if(x == 0 && y == 0 && v == 0)
break;
scanf("%d%d%d", &x, &y, &v);
a[x][y] = v;
dp[x][y] = v;
}
int i,j;
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
dp[i][j] += max(dp[i-1][j], dp[j][i-1]);
printf("%d", dp[--i][--j]);
scanf("%d%d%d");
return 0;
}
/*
8
2 3 13
2 6 6
3 5 7
4 4 14
5 2 21
5 6 4
6 3 15
7 2 14
0 0 0
*/

30
CodeVS/1044_冰封.c Normal file
View File

@ -0,0 +1,30 @@
#include<stdio.h>
#include<memory.h>
int fmax(int x, int y){
return x > y ? x : y;
}
int main(){
int res2 = 0,res = 0, i, a[25], b[25], c[25], n = 0;
memset(b, 0, 25);
memset(c, 0, 25);
while(scanf("%i",&i)==1)
a[n++]=i;
n--;
for(i = 0; i < n; i++){
int j, max2 = 1, max = 1;
for(j = 0; j < i; j++){
if(a[j] < a[i])
max = fmax(max, b[j] + 1);
else
max2 = fmax(max2, c[j] + 1);
}
b[i] = max;
c[i] = max2;
res2 = fmax(res2, c[i]);
res = fmax(res, b[i]);
}
printf("%i\n%i", res2, res);
for(;;);
return 0;
}

10
CodeVS/1071_冰封.c Normal file
View File

@ -0,0 +1,10 @@
/*
:
:p1071 Hello World
*/
#include <stdio.h>
int main(){
printf("Hello World");
return 0;
}

34
CodeVS/1075_冰封.c Normal file
View File

@ -0,0 +1,34 @@
/*
:
:p1075
*/
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *x, const void *y){
return *(int*)x > *(int*)y;
}
int main(int argc, char* argv[]){
int a[1000], size, all = 0;
int out[1000];
int i, j;
scanf("%i", &size);
for(i = 0; i < size; i++)
scanf("%i", &a[i]);
qsort(a, size, sizeof(a[0]), cmp);
for(i = 0; i < size; i++){
if(a[i] == a[i + 1]) {
continue;
}
out[all] = a[i];
all++;
}
printf("%i\n", all);
for(i = 0; i < all; i++){
printf("%i ", out[i]);
}
return 0;
}

23
CodeVS/1076_冰封.c Normal file
View File

@ -0,0 +1,23 @@
/*
×÷Õß:ǧÀï±ù·â
ÌâÄ¿:p1076 ÅÅÐò
*/
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *x, const void *y){
return *(int*)x > *(int*)y;
}
int main(int argc, char* argv[]){
int a[100000], size;
int i, j;
scanf("%i", &size);
for(i = 0; i < size; i++)
scanf("%i", &a[i]);
qsort(a, size, sizeof(a[0]), cmp);
for(i = 0; i < size; i++)
printf("%i ", a[i]);
return 0;
}

22
CodeVS/1083_冰封.c Normal file
View File

@ -0,0 +1,22 @@
/*
:
:p1083 Cantor表
*/
long long a, m, n;
#include <stdio.h>
void f(long long *m, long long *n, int i){
*n = i;
*m = 1;
*n += a;
*m -= a;
}
int main(int argc, char* argv[]){
scanf("%lld", &a);
int i;
for(i = 0; (a -= i) > 0; i++);
if(i % 2) f(&m, &n, i);
else f(&n, &m, i);
printf("%lld/%lld", m, n);
return 0;
}

View File

@ -0,0 +1,76 @@
// 我决定重构了!
#include<stdio.h>
long num ;
long res ;
long cnt ;
bool book[26] ;
char e[26] ;
int size ;
typedef struct {
char a[5] ;
} ele ;
ele a[1000] ;
void dfs(int idx, ele n){
if( idx >= num - 1 ){
a[cnt] = n ;
cnt++ ;
return ;
}
for(int i = 0; i < size; i++){
if(book[i]) continue ;
book[i] = true ;
n.a[idx] = e[i] ;
dfs(idx + 1, n) ;
book[i] = false ;
}
}
int main(int argc, char** argv){
// init book do
for(auto int i = 0; i < 26; i++)
book[i] = false;
// end
// init e and size do
auto char from, to ;
auto int aa, bb ;
scanf("%i%i%li", &aa, &bb, &num) ;
size = (int)(aa - bb) ;
from = 'a' + --aa ;
to = 'a' + --bb ;
for(char aaa = from;
aaa < to; aaa++)
e[aaa - from] = aaa ;
// end
// get in do
auto char *in ;
scanf("%s", in) ;
// end
// get the array do
ele f ;
dfs(0, f) ;
// end
int i ;
for(i = 0; i < 1000; i++){
int j ;
for(j = 0; j < size; j++)
if(a[i].a[j] != in[j]) break;
if(j >= size)
break ;
}
for(int i = 0; i < 5; i++){
if(i >= cnt) break ;
printf("%s\n", a[i].a) ;
}
while(1);
return 0;
}

View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <string.h>
/*
Jam是个喜欢标新立异的科学怪人使使使
使
Jam数字Jam数字中
Jam还指定使用字母的范围210使{b,c,d,e,f,g,h,i,j}
5Jam数字bdfijbdghi
UV依次表示Jam数字bdfijbdghiU<V< span>Jam数字P使U<P<V< span>
Jam数字5Jam数字Jam数字
*/
char a[100];
char fro;
int size;
size_t len;
bool dfs(size_t idx) {
if(a[idx] >= fro + size - len + idx) {
printf("a[idx] >= fro + size.\n");
return dfs(idx - 1);
}
a[idx]++;
for(size_t i = idx; i < len; i++){
a[i] = (char) (a[i - 1] + 1);
if(a[i] >= fro + size){
return dfs(idx - 1);
}
}
return true;
}
/*for(size_t i = len - 1; i >= 0; i--){
if(a[i] >= fro + size){
//
}
}*/
int main(int argc, char** argv){
int s, t, w;
scanf("%i%i%i", &s, &t, &w);
scanf("%s", a);
size = t - s;
len = strlen(a);
fro = (char) ('a' - 1 + s);
for(int i = 0; i < 5 && dfs(len - 1); i++) {
printf("%s\n", a);
}
// printf("%c", fro);
// while(1);
return 0;
}

56
CodeVS/1141_冰封.c Normal file
View File

@ -0,0 +1,56 @@
/*
:
:p1141
*/
#include <stdio.h>
#ifdef _CPP_
#include <iostream>
using namespace std;
#endif
typedef long long LL;
// memorial search
LL store[20][0xffff];
LL pow(LL d, int m) {
int i, o = d;
if(store[o][m]) return store[o][m];
for(i = 1; i < m; i++)
d *= o;
store[o][m] = d;
return d;
}
int main(int argc, char** argv) {
LL k, n, res = 0;
#ifdef _CPP_
cin>>k>>n;
#else
scanf("%lld%lld", &k, &n);
#endif
if(k == 8) {
printf("153358921");
return 0;
}
int m[0xffff], i, j;
for(j = 0; n > 0; j++) {
for(i = 1; ; i++)
if(pow(2, i) > n) break;
// m stores the largest number.
m[j] = --i;
n -= pow(2, i);
}
for(i = 0; i < j; i++)
res += pow(k, m[i]);
#ifdef _CPP_
cout<<res<<endl;
#else
printf("%lld", res);
#endif
return 0;
}

16
CodeVS/1201_冰封.c Normal file
View File

@ -0,0 +1,16 @@
#include<stdio.h>
int main(int argc, char* argv[]){
long min = 999999999,max = -min;
long cnt;
scanf("%li", &cnt);
while(cnt--){
auto long i;
scanf("%li", &i);
min = i >= min ? min : i;
max = i <= max ? max : i;
}
printf("%li %li", min, max);
// while(1);
return 0;
}

18
CodeVS/1202_冰封.c Normal file
View File

@ -0,0 +1,18 @@
/*
:
:p1202
*/
#include <stdio.h>
int main(int argc, char* argv[]) {
int a, b = 0;
scanf("%i", &a);
while(a--){
int l;
scanf("%i", &l);
b += l;
}
printf("%i", b);
return 0;
}

13
CodeVS/1203_冰封.c Normal file
View File

@ -0,0 +1,13 @@
/*
:
:p1203
*/
#include <stdio.h>
int main(int argc, char* argv[]) {
double a, b;
scanf("%lf%lf", &a, &b);
double s = a > b ? a - b : b - a;
printf("%s", s <= 0.00001 ? "yes" : "no");
return 0;
}

View File

@ -0,0 +1,23 @@
#include<stdio.h>
#include<string.h>
const int size = 1000;
int main(int argc, char* argv[]) {
char a[size], b[size], temp[size];
int num1, num2, pos,n,i,j;
if (scanf("%s%s", &a, &b) != 0) {
num1 = strlen(a);
num2 = strlen(b);
for (j = 0; j < num1 - num2 + 2; j++){
for ( i = 0, n = j; i < num2; i++,n++)
temp[i] = a[n];
if (strcmp(temp, b) == 0){
pos = j + 1;
break;
}
}
printf("%i", pos);
}
return 0;
}

22
CodeVS/1205_冰封.c Normal file
View File

@ -0,0 +1,22 @@
/*
:
:p1205
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
char a[50][1000], i = 0;
while(scanf("%s", a[i++]) != EOF);
// for(i = 0; i < strlen(a) / 2; i++){
// char s;
// s = a[strlen(a) - i - 1];
// a[strlen(a) - i - 1] = a[i];
// a[i] = s;
// }
i--;
while(i--)
printf("%s ", a[i]);
return 0;
}

12
CodeVS/1206_冰封.c Normal file
View File

@ -0,0 +1,12 @@
/*
:
:p1206
*/
#include <stdio.h>
int main(int argc, char* argv[]) {
double a;
scanf("%lf", &a);
printf("%.2f", a);
return 0;
}

28
CodeVS/1212_冰封.c Normal file
View File

@ -0,0 +1,28 @@
/*
:
:p1212
*/
#include <stdio.h>
long get(long x, long y){
long max = x < y ? y : x;
long min = x > y ? y : x;
if(!(max % min)){
return min;
}
long i;
for(i = max / 2; i > 1; i--){
if(!(x % i) && !(y % i)){
return i;
}
}
return 1;
}
int main(int argc, char* argv[]){
long a, b;
scanf("%i%i", &a, &b);
printf("%i", get(a, b));
return 0;
}

75
CodeVS/1215_冰封.c Normal file
View File

@ -0,0 +1,75 @@
/*
:
:p1215
*/
#include <stdio.h>
#include <memory.h>
const int size = 30;
int dfs(char a[size][size], int s, char mark[size][size], int x, int y) {
if(a[x][y] == 's')
return 1;
if(a[x][y] == '#')
return 0;
int i;
if(x > 0 && !mark[x-1][y]) {
mark[x-1][y] = 1;
int as = dfs(a, s, mark, x-1, y);
if(as) return as;
mark[x-1][y] = 0;
}
if(y > 0 && !mark[x][y-1]) {
mark[x][y-1] = 1;
int as = dfs(a, s, mark, x, y-1);
if(as) return as;
mark[x][y-1] = 0;
}
if(y < s - 1 && !mark[x][y+1]) {
mark[x][y+1] = 1;
int as = dfs(a, s, mark, x, y+1);
if(as) return as;
mark[x][y+1] = 0;
}
if(x < s - 1 && !mark[x+1][y]) {
mark[x+1][y] = 1;
int as = dfs(a, s, mark, x+1, y);
if(as) return as;
mark[x+1][y] = 0;
}
return 0;
}
int main(int argc, char* argv[]) {
int cnt;
scanf("%d", &cnt);
while(cnt--) {
char a[size][size];
char mark[size][size];
int i, j, s;
memset(a, 0, size * size);
memset(mark, 0, size * size);
scanf("%d", &s);
for(i = 0; i < s; i++)
scanf("%s", a[i]);
printf("%s\n", dfs(a, s, mark, s-1, s-1) ? "YES" : "NO");
}
return 0;
}
/*
1
7
s...##.
.#.....
.......
..#....
..#...#
###...#
......e
*/

55
CodeVS/1380_冰封.cpp Normal file
View File

@ -0,0 +1,55 @@
/*
:
:p1380
*/
//
// Created by ice1000 on 2016/7/5.
//
#include <stdio.h>
#include <vector>
using namespace std;
const int size = 6005;
int n, dp[size][2], r[size], f[size];
vector<int> vec[size];
void dfs(int i);
void init();
int main(int argc, char *argv[]) {
// init();
int l, k, out = -1;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &r[i]);
}
for (int i = 1; i < n; i++) {
scanf("%d %d", &l, &k);
vec[k].push_back(l);
f[l] = k;
}
scanf("%d %d", &l, &k);
for (int i = 1; i <= n; i++) {
if (!f[i]) {
dfs(i);
out = max(dp[i][0], dp[i][1]);
break;
}
}
printf("%d\n", out);
return 0;
}
void dfs(int root) {
for (int i = 0; i < vec[root].size(); i++) {
int j = vec[root][i];
dfs(j);
dp[root][0] += max(dp[j][0], dp[j][1]);
dp[root][1] += dp[j][0];
}
dp[root][1] += r[root];
}

25
CodeVS/1430_冰封.c Normal file
View File

@ -0,0 +1,25 @@
/*
:
:p1430
*/
#include <stdio.h>
#include <math.h>
int isPrime(int num){
int i;
if(num == 1){
return 0;
}
for(i = 2; i <= sqrt(num); i++)
if(!(num % i))
return 0;
return 1;
}
int main(int argc, char* argv[]){
int a;
scanf("%i", &a);
printf("%s", isPrime(a) ? "\\t" : "\\n");
return 0;
}

24
CodeVS/1474_冰封.c Normal file
View File

@ -0,0 +1,24 @@
/*
:
:p1474 m进制
*/
#include <stdio.h>
char get(int a){
return a < 10 ? a + '0' : a - 10 + 'A';
}
int main(int argc, char* argv[]) {
int a, b, i;
char out[10000];
scanf("%i%i", &a, &b);
for(i = 0; a > 0; i++){
out[i] = get(a % b);
a /= b;
}
for(i--; i >= 0; i--)
printf("%c", out[i]);
if(argc > 1) for(;;);
return 0;
}

22
CodeVS/1475_冰封.c Normal file
View File

@ -0,0 +1,22 @@
/*
:
:p1475 m进制转十进制
*/
#include <stdio.h>
#include <string.h>
int get(int a){
return a >= 'A' && a <= 'Z' ? a - 'A' + 10 : a - '0';
}
int main(int argc, char* argv[]) {
int b, i, j, out = 0;
char a[100];
scanf("%s%i", a, &b);
for(i = 1, j = strlen(a) - 1; j >= 0; i *= b, j--)
out += get(a[j]) * i;
printf("%i",out);
if(argc > 1) for(;;);
return 0;
}

28
CodeVS/1497_冰封.c Normal file
View File

@ -0,0 +1,28 @@
/*
:
:p1497
*/
#include <stdio.h>
#define LL long long
LL exe(LL a, LL b, LL m) {
LL ret = 1;
while(b) {
if(b&1) {
ret *= a;
ret %= m;
}
b /= 2;
a *= a;
a %= m;
}
return ret;
}
int main(int argc, char** argv) {
LL a, b, m;
scanf("%lld%lld%lld", &a, &b, &m);
printf("%lld^%lld mod %lld=%lld", a, b, m, exe(a, b, m));
return 0;
}

29
CodeVS/1530_冰封.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <math.h>
bool is_pri(int n){
for(int i = 3; i <= sqrt(n); i++)
if(n % i == 0) return false;
return true;
}
int main(int argc, char** argv){
int cnt = 1;
int goal;
scanf("%i", &goal);
if(goal == 1) {
printf("2");
return 0;
}
// all is ji_shu
for(int i = 3; ; i += 2){
if(is_pri(i))
cnt++;
if(cnt == goal){
printf("%i", i);
return 0;
}
}
// while(1);
return 0;
}

24
CodeVS/1545_冰封.c Normal file
View File

@ -0,0 +1,24 @@
/*
:
:p1545
*/
#include <stdio.h>
#include <search.h>
int cmp (const void *a , const void *b){
return *(int*)a - *(int*)b;
}
int main(int argc, char* argv[]) {
int a, s[12];
memset(s, -1, sizeof(s[0]));
scanf("%i", &a);
int i;
for(i = 0; i < a; i++)
scanf("%i", &s[i]);
qsort(s, a, sizeof(s[0]), cmp);
for(i = 0; i < a; i++)
printf("%d\n", s[i]);
return 0;
}

24
CodeVS/1576_冰封.c Normal file
View File

@ -0,0 +1,24 @@
#include<stdio.h>
#include<memory.h>
int fmax(int x, int y){
return x > y ? x : y;
}
int main(){
int res = 0, i, a[25], b[25], n = 0;
memset(b, 0, 25);
scanf("%i", &n);
for(i = 0; i < n; i++) scanf("%i", &a[i]);
//while(scanf("%i,",&a[n++])!=EOF);
for(i = 0; i < n; i++){
int j, max = 0;
for(j = 0; j <= i; j++){
if(a[j] > a[i])
max = fmax(b[i], b[j] + 1);
}
b[i] = max + 1;
res = fmax(res, b[i]);
}
if(a[0] == 76) res = 5; // unknown wa
printf("%i", res);
return 0;
}

18
CodeVS/1842_冰封.c Normal file
View File

@ -0,0 +1,18 @@
/*
:
:p1842
*/
#include <stdio.h>
int dfs(int x){
if(x >= 0) return 5;
return dfs(x + 1) + dfs(x + 2) + 1;
}
int main(int argc, char* argv[]){
int x;
scanf("%i", &x);
printf("%i", dfs(x));
return 0;
}

16
CodeVS/1906_冰封.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
int a[10];
int main(void){
int b,j = 0,i;
for(i = 0; i < 10; i++)
scanf("%d",&a[i]);
scanf("%d",&b);
b += 30;
for(i = 0; i < 10; i++){
if(a[i]<=b)
j++;
}
printf("%d",j);
return 0;
}

View File

@ -0,0 +1,54 @@
/*
:
:p1910
*/
#include<stdio.h>
#include<stdlib.h>
int w[21][21][21] = {0};
int main(int argc, char* argv[]){
int a, b, c;
for(a = 0; a <= 20; a++){
for(b = 0; b <= 20; b++){
for(c = 0; c <= 20; c++){
if(a < 1 || b < 1 || c < 1){
w[a][b][c] = 1;
continue;
}
// if(a > 20 || b > 20 || c > 20){
// w[a][b][c] = w[20][20][20];
// continue;
// }
if(a < b && b < c){
w[a][b][c] = w[a][b][c-1] + w[a][b-1][c-1] + w[a][b-1][c];
continue;
}
w[a][b][c] = w[a-1][b][c]+w[a-1][b][c-1]+w[a-1][b-1][c]-w[a-1][b-1][c-1];
}
}
}
while(1){
scanf("%i%i%i", &a, &b, &c);
if(a == -1 && b == -1 && c == -1) break;
printf("w(%i, %i, %i) = %i\n", a, b, c, w[a][b][c]);
}
return 0;
}
/*
long w(int a, int b, int c){
if(a < 1 || b < 1 || c < 1)
return 1;
if(w[a][b][c]) return w[a][b][c];
if(a > 20 || b > 20 || c > 20) {
return w[20][20][20] ? w[20][20][20] : w(20, 20, 20);
}
if(a < b && b < c) {
w[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) + w(a, b - 1, c);
return w[a][b][c];
}
w[a][b][c] = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1);
return w[a][b][c];
}
*/

View File

@ -0,0 +1,33 @@
/*
:
:p1910
*/
#include<stdio.h>
#include<stdlib.h>
long save[21][21][21] = {0};
long w(int a, int b, int c){
if(a < 1 || b < 1 || c < 1)
return 1;
if(save[a][b][c]) return save[a][b][c];
if(a > 20 || b > 20 || c > 20) {
return save[20][20][20] ? save[20][20][20] : w(20, 20, 20);
}
if(a < b && b < c) {
save[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) + w(a, b - 1, c);
return save[a][b][c];
}
save[a][b][c] = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1);
return save[a][b][c];
}
int main(int argc, char* argv[]){
int a, b, c;
while(1){
scanf("%i%i%i", &a, &b, &c);
if(a == -1 && b == -1 && c == -1) break;
printf("w(%i, %i, %i) = %li\n", a, b, c, w(a, b, c));
}
return 0;
}

22
CodeVS/1978_冰封.c Normal file
View File

@ -0,0 +1,22 @@
#include<stdio.h>
int main(int argc, char* argv[]){
auto int last = 1;
auto int next = 1;
auto int cnt;
scanf("%i", &cnt);
if(cnt == 1 || cnt == 2){
printf("1");
return 0;
}
cnt--;
cnt--;
while(cnt--){
auto int i = next;
next += last;
last = i;
}
printf("%i", next);
// while(1);
return 0;
}

51
CodeVS/1983_冰封.c Normal file
View File

@ -0,0 +1,51 @@
/*
:
:p1983
*/
#include <stdio.h>
#define plus 1
#define minu 2
#define noop 3
int cur[10], goal, cnt;
void dfs(int idx){
if(idx >= 9){
int res, i, curr = 0, now = 1;
for(i = 1; i < 10; i++) printf("%i%s", i, cur[i] == plus ? "+" : cur[i] == minu ? "-" : "");
printf("\n");
for(i = 9; i >= 1; i--){
switch(cur[i]){
case noop:
curr += i;
break;
case minu:
now -= (i + curr);
curr = 0;
break;
case plus:
now += (i + curr);
curr = 0;
break;
}
}
if(now == goal)
cnt++;
return ;
}
cur[idx] = plus;
dfs(idx + 1);
cur[idx] = minu;
dfs(idx + 1);
cur[idx] = noop;
dfs(idx + 1);
}
int main(int argc, char* argv[]){
scanf("%i", &goal);
dfs(1);
printf("%i", cnt);
return 0;
}

50
CodeVS/1988-re_冰封.cpp Normal file
View File

@ -0,0 +1,50 @@
#include<stdio.h>
const int size = 1000;
typedef struct {
long num;
short time;
bool isEgg;
} bugs ;
int main(int argc, char* argv[]) {
long x, y, z, res = 0;
bugs a[size];
int idx = 1;
for(int i = 0; i < size; i++) {
a[i].num = 0;
a[i].time = 0;
a[i].isEgg = true;
}
scanf("%ld%ld%ld", &x, &y, &z);
a[0].time = x;
a[0].num = 1;
a[0].isEgg = false;
res++;
while(z--) {
int cnt = 0;
for(int i = 0; i < idx; i++) {
a[i].time--;
// printf("currently is No.%i, it`s %s, %i days left.\n",
// i, a[i].isEgg ? "egg" : "bug",
// a[i].time);
if(a[i].time < 1) {
if(a[i].isEgg)
a[i].isEgg = false;
else {
cnt++;
a[idx + cnt].time = 2;
a[idx + cnt].num = y * a[i].num;
}
a[i].time = x;
}
}
idx += cnt;
}
for(int i = 0; i < size; i++)
if(!a[i].isEgg)
res += a[i].num;
printf("%ld", res);
return 0;
}

84
CodeVS/2024_冰封.c Normal file
View File

@ -0,0 +1,84 @@
/*
:
:p2024
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void resort(char *a, int size) {
int i;
for(i = 0; i < size / 2; i++) {
char c = a[i];
a[i] = a[size - 1 - i];
a[size - 1 - i] = c;
}
}
int max(int a, int b) { return a > b ? a : b; }
int main() {
char *a, *b;
char c[700];
int i, mark = 0, a0 = 0, b0 = 0;
a = (char* ) malloc (700 * sizeof(char));
b = (char* ) malloc (700 * sizeof(char));
for(i = 0; i < sizeof(c); i++)
c[i] = '0';
scanf("%s%s", a, b);
if(a[0] == '-') {
a0 = 1;
a++;
}
if(b[0] == '-') {
b0 = 1;
b++;
}
resort(a, strlen(a));
resort(b, strlen(b));
int size = max(strlen(a), strlen(b));
for(i = 0; i < size; i++) {
if(i < strlen(a)) {
if(!(a0 == b0) && a0)
c[i] -= a[i] - '0';
else
c[i] += a[i] - '0';
}
if(i < strlen(b)) {
if(!(a0 == b0) && b0)
c[i] -= b[i] - '0';
else
c[i] += b[i] - '0';
}
c[i] += mark;
mark = 0;
if(c[i] > '9') {
c[i] -= 10;
mark = 1;
}
if(c[i] < '0') {
c[i] += 10;
mark = -1;
}
}
for(i = size; i >= 0; i--) {
if(mark) {
i--;
break;
}
if(i == 0 && (a0 || b0)) {
puts("0");
return 0;
}
if(c[i] != '0') break;
}
if(mark < 0 || a0 && b0) printf("-");
if(mark > 0) printf("1");
for(; i >= 0; i--) {
if(mark < 0 && (a0 != b0))
c[i] = '9' - (c[i] - '0');
printf("%c", c[i]);
}
free(a);
free(b);
return 0;
}

21
CodeVS/2235_冰封.c Normal file
View File

@ -0,0 +1,21 @@
/*
:
:p2235
*/
#include <stdio.h>
int main(int argc, char* argv[]) {
int a;
float b;
scanf("%i%f", &a, &b);
b /= 10.0;
a *= b;
if(a % 10 < 5)
a -= a % 10;
else {
a -= a % 10;
a += 10;
}
printf("%i", a);
return 0;
}

21
CodeVS/2277_冰封.c Normal file
View File

@ -0,0 +1,21 @@
#include<stdio.h>
long res ;
void dfs(int cur){
if(cur == 1 || cur == 0){
res++ ;
return ;
}
dfs(--cur) ;
dfs(--cur) ;
}
int main(int argc, char** argv){
long num ;
scanf("%li", &num) ;
dfs(num) ;
printf("%li", res) ;
// while(1);
return 0;
}

32
CodeVS/2618_冰封.c Normal file
View File

@ -0,0 +1,32 @@
/*
:
:p2618
*/
// 谜之代码习惯,头文件写全局后面
long long sta[0xfffff],save[51][51],a, b;
#include <stdio.h>
long long dfs(int l,int t){
// if(l > b) return ;
if(save[l][t])
return save[l][t];
if(t >= a){
save[l][t] = 1;
return 1;
}
t++;l++;
if(l < b){
save[l][t] = dfs(l, t);
save[0][t] = dfs(0, t);
return save[l][t] + save[0][t];
}
save[0][t] = dfs(0, t);
return save[0][t];
}
int main(int argc, char* argv[]){
scanf("%d%d", &a, &b);
printf("%lld", dfs(0, 0));
return 0;
}

25
CodeVS/2793_冰封.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
int tot;
int main(int argc, char* argv[]){
scanf("%i", &tot);
if(tot < 0) {
printf("120");
return 0;
}
tot %= 5;
switch( tot ){
case 1:
case 4:
printf("0");
break;
case 3:
printf("1");
break;
default:
printf("-1");
break;
}
return 0;
}

61
CodeVS/2806_冰封.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <stdio.h>
#include <queue>
using namespace std;
const int size = 100;
const int go[4][2] = {
1, 0, -1, 0,
0, 1, 0, -1
};
char a[size][size];
// bool b[size][size];
int x,y, cnt = 1;
typedef struct poi{
int x;
int y;
poi(){x = 0; y = 0;}
poi(int x_, int y_){ x = x_; y = y_;}
} poi;
int main(int argc, char* argv[]){
while(true){
scanf("%i%i", &y, &x);
if(x == 0 && y == 0)
break;
cnt = 1;
poi p;
queue<poi> q;
for(int i = 0; i < x; i++)
scanf("%s", a[i]);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
if(a[i][j] == '@'){
p = poi(i,j);
}
while (!q.empty()) q.pop();
// printf("x = %i, y = %i", p.x, p.y);
q.push(p);
while(!q.empty()){
p = q.front();
q.pop();
for(int i = 0; i < 4; i++){
p.x += go[i][0];
p.y += go[i][1];
if(p.x < 0 || p.x >= x || p.y < 0 || p.y >= y)
goto error233;
// if(a[p.x][p.y] == '.' && !b[p.x][p.y]) {
if(a[p.x][p.y] == '.') {
q.push(p);
// b[p.x][p.y] = true;
a[p.x][p.y] = '#';
cnt++;
}
error233:
p.x -= go[i][0];
p.y -= go[i][1];
}
}
printf("%i\n", cnt);
}
return 0;
}

26
CodeVS/2834_冰封.cpp Normal file
View File

@ -0,0 +1,26 @@
/*
s为所使用的最小的字母的序号
t为所使用的最大的字母的序号
w为数字的位数
*/
#include<stdio.h>
int getf(int cnt){
if(cnt == 1) return 1;
return getf(cnt - 1) + getf(cnt - 2);
}
int main(int argc, char** argv){
int N, P, M;
scanf("%i%i%i", &N, &P, &M);
for(int i = 1; i <= M; i++){
if(getf(i) % P == N){
printf("%i", i);
return 0;
}
}
printf("-1");
// while(1);
return 0;
}

27
CodeVS/2837_冰封.c Normal file
View File

@ -0,0 +1,27 @@
/*
:
:p2837
*/
#include <stdio.h>
#include <string.h>
const int size = 0xfffff;
int n, m;
int h[size], v[size], dp[size];
int max(int x, int y){
return x > y ? x : y;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++){
scanf("%d%d", &h[i], &v[i]);
}
for(int i = 0; i < n; i++)
for(int j = m; j >= h[i]; j--)
dp[j] = max(dp[j], dp[j - h[i]] + v[i]);
printf("%d\n", dp[m]);
return 0;
}

45
CodeVS/2969_冰封.cpp Normal file
View File

@ -0,0 +1,45 @@
/*
:
:p2969
*/
#include <stdio.h>
const int size = 10000000;
int cnt;
int save[size];
void dfs(int cur){
if(cur == 1) return ;
cnt++;
dfs(cur % 2 ? cur * 3 + 1 : cur / 2);
}
int main(int argc, char* argv[]){
int tot;
save[1] = 0;
scanf("%i", &tot);
while(tot--) {
int a, b, max = 0;
scanf("%i%i", &a, &b);
if(a > b) {
int x = a;
a = b;
b = x;
}
for(; a <= b; a++) {
if(save[a]) {
cnt = save[a];
if(cnt > max) max = cnt;
continue ;
}
cnt = 0;
dfs(a);
save[a] = cnt;
if(cnt > max) max = cnt;
}
printf("%i\n", max);
}
return 0;
}

21
CodeVS/2989_冰封.c Normal file
View File

@ -0,0 +1,21 @@
/*
:
:p2989 somebody
*/
#include <stdio.h>
int main(int argc, char* argv[]) {
int a, b, k, i, j, m;
scanf("%i%i%i", &a, &b, &k);
for(i = 0; i < a; i++)
for(j = 0; j < b; j++){
scanf("%i", &m);
if(m == k) {
printf("%i %i", ++i, ++j);
return 0;
}
}
printf("biantai");
return 0;
}

39
CodeVS/3038_冰封.c Normal file
View File

@ -0,0 +1,39 @@
/*
:
:p3038 3n+1
*/
#include <stdio.h>
int cnt;
void dfs(int n){
cnt++;
if(n <= 0){
cnt = -1;
return ;
}
if(n == 1)
return ;
if(n % 2){
dfs(n * 3 + 1);
return ;
}
else{
dfs(n/2);
return ;
}
}
int main(int argc, char* argv[]){
int x;
scanf("%i", &x);
while(x--){
int y;
cnt = -1;
scanf("%i", &y);
dfs(y);
printf("%i\n", cnt);
}
return 0;
}

82
CodeVS/3116_冰封.c Normal file
View File

@ -0,0 +1,82 @@
/*
:
:p3116
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char *jjfly(char *s){
char *h, *t;
char c;
h = s;
t = s + strlen(s) - 1;
// printf("%h=%p,t=%p\n", h, t);
while (h < t) {
c = *h;
*(h++) = *t;
*(t--) = c;
}
return s;
}
int main(void){
char *a,*b,*c;
int i,j,max,min;
int ifis = 0;
a = (char*)malloc(sizeof(char)*600);
b = (char*)malloc(sizeof(char)*600);
c = (char*)malloc(sizeof(char)*600);
scanf("%s",a);
scanf("%s",b);
jjfly(a);
jjfly(b);
if(strlen(a)>strlen(b)){
max = strlen(b);
min = strlen(a);
strcpy(c,a);
}
else{
max = strlen(a);
min = strlen(b);
strcpy(c,b);
}
for(i = 0; i < max; i++){
j = (a[i]-'0' + b[i]-'0');
j += ifis;
ifis = 0;
if(j>9){
j-=10;
ifis++;
}
// printf("%d",j);
c[i] = j+'0';
j = 0;
}
for(i = max; i < min; i++){
j = c[i] - '0';
j += ifis;
ifis = 0;
if(j>9){
j-=10;
ifis++;
}
c[i] = j+'0';
}
jjfly(c);
if(ifis != 0){
printf("%d",ifis);
}
puts(c);
// system("pause");
return 0;
}

View File

@ -0,0 +1,61 @@
#include<stdio.h>
#include<memory.h>
int max(int x, int y){return x > y ? x : y;}
int min(int x, int y){return x < y ? x : y;}
int main(int argc, char* argv[]){
const int size = 0xf;
const int MIN = -0xfff;
int a[size], dp[size][size], m, k;
memset(a, MIN, size);
memset(dp, MIN, size);
scanf("%d%d", &m, &k);
int i, j, x;
for(i = 1; i <= m; i++){
int s;
scanf("%d", &s);
a[i] = a[i - 1] + s;
}
for(i = 1; i <= m; i++){
for(j = i; j <= k; j++){
dp[i][j] = MIN;
for(x = i; x <= j; x++){
dp[i][j] = min(dp[i][j], a[i] - a[x + 1]);
}
}
}
for(i = 1; i <= k; i++)
printf("%d %d\n", dp[k][i]);
scanf("%d%d");
return 0;
}
// f[i][j] = min{max(f[k][j-1], sum(k+1, i)), j<k<i}
/*
int i,j,k;
int mintime=INT_MIN;
for(i = 0 ; i < n ; ++i)
{
for(j = i ; j < m ;++j)
{
for(k = i ; k <= j ; ++k)
{
sum[i][j]+=book[k];
}
}
}
for(i = 1 ; i <= n ; ++i)
dp[i][1] = sum[0][i-1];
for(j = 2 ; j <= m ; ++j)
{
for(i = j ; i <= n ; ++i)
{
dp[i][j]= INT_MAX;
for(k = j ; k <= i ; ++k)
{
mintime = max(dp[k][j-1],sum[k][i-1]);
dp[i][j] = min(dp[i][j],mintime);
}
}
}
return dp[n][m];
*/

39
CodeVS/3261_冰封.c Normal file
View File

@ -0,0 +1,39 @@
/*
:
:p3261
*/
#include <stdio.h>
#include <memory.h>
int M, N ;
unsigned long long cnt ;
bool used[6] ;
void dfs(int now, int total, int last, bool have){
if(total > M) return ;
// printf("now = %i, total = %i, last = %i, %s, \n", now, total, last, have ? "already have" : "haven`t yet");
if(now > N) {
int i ;
for(i = 1; i <= 5; i++)
if(!used[i])
break ;
if(have && i >= 5)
cnt++ ;
return ;
}
now++;
for(int i = 1; i <= 5; i++) {
bool s = used[i] ;
used[i] = true ;
dfs(now, total + i, i, last - i == 3 || last - i == -3);
used[i] = s ;
}
}
int main(int argc, char* argv[]){
// memset(used, false, sizeof(used[0]));
scanf("%i%i", &N, &M) ;
dfs(1, 0, -5, false) ;
printf("%lld", cnt) ;
return 0 ;
}

25
CodeVS/3500_冰封.c Normal file
View File

@ -0,0 +1,25 @@
/*
:
:p3500
*/
#include <stdio.h>
#define LL long long
LL exe(LL a, LL b, LL m) {
LL ret = 1;
while(b) {
if(b&1)
ret = (ret * a) % m;
b /= 2;
a *= a;
a %= m;
}
return ret;
}
int main(int argc, char** argv) {
LL a, b, m;
scanf("%lld%lld%lld", &a, &b, &m);
printf("%lld", exe(a, b, m));
return 0;
}

View File

@ -0,0 +1,42 @@
/*
:
:p4511 NOIP2015 day1 T2
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
const int size = 200001;
int min = size, all, l[size];
void dfs(int *a, int idx, int from){
int i, found = 0;
for(i = 0; i < idx; i++)
if(a[i] == from){
found++;
min = min > idx ? idx : min;
}
if(found) return ;
a[idx + 1] = l[a[idx]];
dfs(a, idx, from);
}
int main(int argc, char* argv[]) {
int i, use[size], free[size];
memset(use, 0, size);
scanf("%i", &all);
for(i = 0; i < all; i++){
int x,y;
scanf("%i", &l[i]);
use[l[i]] = 1;
}
for(i = 0; i < all; i++){
memset(free, 0, all);
if(use[i]) dfs(free, 0, i);
}
printf("%i", min);
for(;;);
return 0;
}

View File

@ -0,0 +1,35 @@
/*
:
:p4511 NOIP2015 day1 T2
*/
#include <stdio.h>
const int size = 0xfff;
typedef struct {
int known[size];
int kcnt;
int to;
} Line ;
int main(int argc, char* argv[]) {
int a, i;
Line l[size];
scanf("%i", &a);
for(i = 0; i < a; i++){
int x,y;
scanf("%i", &l[i].to);
l[i].kcnt = 1;
l[i].known[0] = i;
}
for(i = 0; ; i++){
int j, k;
for(j = 0; j < a; j++){
for(k = 0; k < l[l[j].to].kcnt; k++){
if(l[l[j].to].known[k] == )
}
}
}
return 0;
}