mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
commit
86e65f21a9
42
CWOJ/1193_冰封.cpp
Normal file
42
CWOJ/1193_冰封.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#define LL long long
|
||||
|
||||
LL fast_plus(LL a, LL b, LL m) {
|
||||
LL ret = 0;
|
||||
while(b) {
|
||||
if(b & 1)
|
||||
ret = (ret + a) % m;
|
||||
b >>= 1;
|
||||
a = (a << 1) % m;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LL fast_pow(LL a, LL b, LL m) {
|
||||
LL ret = 1;
|
||||
while(b) {
|
||||
if(b & 1)
|
||||
ret = fast_plus(ret, a, m);
|
||||
b >>= 1;
|
||||
a = fast_plus(a, a, m);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
LL n, m, t, aa = 0;
|
||||
char a[10005];
|
||||
std::cin>>a>>n>>m;
|
||||
for(i = 0; i < strlen(a); i++)
|
||||
aa = (aa * 10 + a[i] - '0') % m;
|
||||
if(n == 1) {
|
||||
std::cout<<a<<' '<<fast_pow(aa, 2, m);
|
||||
return 0;
|
||||
}
|
||||
t = fast_pow(aa, n, m);
|
||||
std::cout<<t<<' '<<fast_plus(t, aa, m);
|
||||
return 0;
|
||||
}
|
71
CWOJ/1204_冰封.c
Normal file
71
CWOJ/1204_冰封.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
typedef long long LL;
|
||||
|
||||
#define _CPP_
|
||||
#ifdef _CPP_
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
int isp(int a, int p[10000], size_t s) {
|
||||
if(!a || a == 1) return 0;
|
||||
int i;
|
||||
for(i = 0; i < s; i++)
|
||||
if(!(a % p[i]))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, cnt, p[10000], ps = 0;
|
||||
// memset(p, 0, sizeof(p));
|
||||
for(i = 2; i < 35000; i++) {
|
||||
if(isp(i, p, ps)) {
|
||||
p[ps] = i;
|
||||
ps++;
|
||||
}
|
||||
}
|
||||
scanf("%d", &cnt);
|
||||
while(cnt--) {
|
||||
int i, l = 0, g = 1, z = 1, f = 0, s = 0, t = 1, started = 0;
|
||||
int *c = (int*) malloc (ps * sizeof(int));
|
||||
memset(c, 0, ps);
|
||||
LL a, o;
|
||||
#ifdef _CPP_
|
||||
cin>>a;
|
||||
#else
|
||||
scanf("%lld", &a);
|
||||
#endif
|
||||
o = a;
|
||||
for(i = 0; i < ps; i++) {
|
||||
if(a == 1) break;
|
||||
if(!(a % p[i]) && p[i] != o || a == p[i]) {
|
||||
if(o == p[i] && o != 2) z = 0;
|
||||
a /= p[i];
|
||||
c[i]++;
|
||||
i--, l++;
|
||||
}
|
||||
}
|
||||
s = ++i;
|
||||
for(i = 0; i < s; i++) {
|
||||
if(c[i] > 1) g = 0;
|
||||
t *= c[i] + 1;
|
||||
if(c[i]) started++;
|
||||
if(started && !c[i]) z = 0;
|
||||
}
|
||||
free(c);
|
||||
if(t % 3) f++;
|
||||
// printf("%s%s%s%s\n", g ? "G" : "", z ? "Z" : "", f ? "F" : "",
|
||||
// (!g && !z && !f) ? "FUCK" : "");
|
||||
|
||||
if(t % 3) f++;
|
||||
if(g) printf("G");
|
||||
if(z) printf("Z");
|
||||
if(f) printf("F");
|
||||
if(!g && !z && !f) printf("FUCK");
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
70
CWOJ/2198-re_冰封.c
Normal file
70
CWOJ/2198-re_冰封.c
Normal file
|
@ -0,0 +1,70 @@
|
|||
#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(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;
|
||||
}
|
5
CodeVS/1000_冰封.pas
Normal file
5
CodeVS/1000_冰封.pas
Normal file
|
@ -0,0 +1,5 @@
|
|||
var a, b:longint;
|
||||
begin
|
||||
readln(a,b);
|
||||
writeln(a+b);
|
||||
end.
|
86
CodeVS/1001_冰封.cpp
Normal file
86
CodeVS/1001_冰封.cpp
Normal 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
20
CodeVS/1007_冰封.c
Normal 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
39
CodeVS/1010_冰封.c
Normal 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
20
CodeVS/1011_冰封.c
Normal 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;
|
||||
}
|
21
CodeVS/1012-unfinished_冰封.c
Normal file
21
CodeVS/1012-unfinished_冰封.c
Normal 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
24
CodeVS/1014_冰封.c
Normal 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
19
CodeVS/1023_冰封.c
Normal 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;
|
||||
}
|
35
CodeVS/1025-unfinished_冰封.c
Normal file
35
CodeVS/1025-unfinished_冰封.c
Normal 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
49
CodeVS/1031_冰封.c
Normal 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;
|
||||
}
|
37
CodeVS/1043-unfinished_冰封.c
Normal file
37
CodeVS/1043-unfinished_冰封.c
Normal 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
30
CodeVS/1044_冰封.c
Normal 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
10
CodeVS/1071_冰封.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
作者:千里冰封
|
||||
题目:p1071 Hello World
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
int main(){
|
||||
printf("Hello World");
|
||||
return 0;
|
||||
}
|
34
CodeVS/1075_冰封.c
Normal file
34
CodeVS/1075_冰封.c
Normal 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
23
CodeVS/1076_冰封.c
Normal 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
22
CodeVS/1083_冰封.c
Normal 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;
|
||||
}
|
76
CodeVS/1140-failed_冰封.cpp
Normal file
76
CodeVS/1140-failed_冰封.cpp
Normal 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;
|
||||
}
|
53
CodeVS/1140-unfinished_冰封.cpp
Normal file
53
CodeVS/1140-unfinished_冰封.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/*
|
||||
Jam是个喜欢标新立异的科学怪人。他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩。
|
||||
在他的计数法中,每个数字的位数都是相同的(使用相同个数的字母)英文字母按原先的顺序,排在前面的字母小于排在它后面的字母。
|
||||
我们把这样的“数字”称为Jam数字。在Jam数字中,每个字母互不相同,而且从左到右是严格递增的。
|
||||
每次,Jam还指定使用字母的范围,例如,从2到10,表示只能使用{b,c,d,e,f,g,h,i,j}这些字母。
|
||||
如果再规定位数为5,那么,紧接在Jam数字“bdfij”之后的数字应该是“bdghi”。
|
||||
(如果我们用U、V依次表示Jam数字“bdfij”与“bdghi”,则U<V< span>,且不存在Jam数字P,使U<P<V< span>)。
|
||||
你的任务是:
|
||||
对于从文件读入的一个Jam数字,按顺序输出紧接在后面的5个Jam数字,如果后面没有那么多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
56
CodeVS/1141_冰封.c
Normal 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
16
CodeVS/1201_冰封.c
Normal 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
18
CodeVS/1202_冰封.c
Normal 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
13
CodeVS/1203_冰封.c
Normal 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;
|
||||
}
|
23
CodeVS/1204-unfinished_冰封.c
Normal file
23
CodeVS/1204-unfinished_冰封.c
Normal 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
22
CodeVS/1205_冰封.c
Normal 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
12
CodeVS/1206_冰封.c
Normal 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
28
CodeVS/1212_冰封.c
Normal 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
75
CodeVS/1215_冰封.c
Normal 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
55
CodeVS/1380_冰封.cpp
Normal 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
25
CodeVS/1430_冰封.c
Normal 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
24
CodeVS/1474_冰封.c
Normal 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
22
CodeVS/1475_冰封.c
Normal 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
28
CodeVS/1497_冰封.c
Normal 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
29
CodeVS/1530_冰封.cpp
Normal 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
24
CodeVS/1545_冰封.c
Normal 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
24
CodeVS/1576_冰封.c
Normal 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
18
CodeVS/1842_冰封.c
Normal 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
16
CodeVS/1906_冰封.c
Normal 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;
|
||||
}
|
54
CodeVS/1910-also-wasted_冰封.c
Normal file
54
CodeVS/1910-also-wasted_冰封.c
Normal 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];
|
||||
}
|
||||
*/
|
33
CodeVS/1910-wasted_冰封.c
Normal file
33
CodeVS/1910-wasted_冰封.c
Normal 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
22
CodeVS/1978_冰封.c
Normal 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
51
CodeVS/1983_冰封.c
Normal 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
50
CodeVS/1988-re_冰封.cpp
Normal 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
84
CodeVS/2024_冰封.c
Normal 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
21
CodeVS/2235_冰封.c
Normal 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
21
CodeVS/2277_冰封.c
Normal 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
32
CodeVS/2618_冰封.c
Normal 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
25
CodeVS/2793_冰封.c
Normal 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
61
CodeVS/2806_冰封.cpp
Normal 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
26
CodeVS/2834_冰封.cpp
Normal 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
27
CodeVS/2837_冰封.c
Normal 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
45
CodeVS/2969_冰封.cpp
Normal 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
21
CodeVS/2989_冰封.c
Normal 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
39
CodeVS/3038_冰封.c
Normal 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
82
CodeVS/3116_冰封.c
Normal 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;
|
||||
}
|
61
CodeVS/3162-still-unfinished_冰封.c
Normal file
61
CodeVS/3162-still-unfinished_冰封.c
Normal 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
39
CodeVS/3261_冰封.c
Normal 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
25
CodeVS/3500_冰封.c
Normal 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;
|
||||
}
|
42
CodeVS/4511-also-unfinished_冰封.c
Normal file
42
CodeVS/4511-also-unfinished_冰封.c
Normal 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;
|
||||
}
|
35
CodeVS/4511-unfinished_冰封.c
Normal file
35
CodeVS/4511-unfinished_冰封.c
Normal 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;
|
||||
}
|
2
CodeVS/Readme.md
Normal file
2
CodeVS/Readme.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
#CodeVS
|
||||
[Goto Home Page](http://www.codevs.cn/ "Welcome to CodeVS")
|
26
Codeforces/705A.cpp
Normal file
26
Codeforces/705A.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <cstdio>
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
for(int i=0;i<n-1;i++)
|
||||
{
|
||||
if(i%2==0)
|
||||
{
|
||||
printf("I hate that ");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("I love that ");
|
||||
}
|
||||
}
|
||||
if(n%2==1)
|
||||
{
|
||||
printf("I hate it\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("I love it\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
18
Codeforces/705B.cpp
Normal file
18
Codeforces/705B.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
long long sum=0;
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
int tmp;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&tmp);
|
||||
sum=sum+tmp-1;
|
||||
printf("%d\n",2-!!(sum&1));
|
||||
}
|
||||
return 0;
|
||||
}
|
36
Codeforces/705B_2.cpp
Normal file
36
Codeforces/705B_2.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
int tmp;
|
||||
int a0=0;
|
||||
int a1=0;
|
||||
int laststate=2;
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
scanf("%d",&tmp);
|
||||
if(tmp==1)
|
||||
{
|
||||
printf("%d\n",laststate);
|
||||
continue;
|
||||
}
|
||||
if(tmp%2==0) a0++;
|
||||
else a1++;
|
||||
if(a1%2==1)
|
||||
{
|
||||
laststate=2-((a0+a1)%2==0);
|
||||
printf("%d\n",laststate);
|
||||
}
|
||||
else
|
||||
{
|
||||
laststate=2-((a0+a1)%2==1);
|
||||
printf("%d\n",laststate);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
84
Codeforces/705D.cpp
Normal file
84
Codeforces/705D.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
#define MAXN 5005
|
||||
|
||||
#define INF 10000000000000LL
|
||||
using LL = long long;
|
||||
|
||||
LL a[MAXN];
|
||||
LL b[MAXN];
|
||||
LL c[MAXN];
|
||||
LL d[MAXN];
|
||||
LL x[MAXN];
|
||||
LL dis[MAXN][MAXN];
|
||||
|
||||
LL nextpos[MAXN];
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int n,StartPoint,EndPoint;
|
||||
scanf("%d %d %d",&n,&StartPoint,&EndPoint);
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%lld",&x[i]);
|
||||
}
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%lld",&a[i]);
|
||||
}
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%lld",&b[i]);
|
||||
}
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%lld",&c[i]);
|
||||
}
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%lld",&d[i]);
|
||||
}
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
for(int j=1;j<=n;j++)
|
||||
{
|
||||
if(i==j) {dis[i][j]=0;continue;}
|
||||
if(j>i)
|
||||
{
|
||||
dis[i][j]=abs(x[i]-x[j])+d[i]+a[j];
|
||||
}
|
||||
else /// (j<i)
|
||||
{
|
||||
dis[i][j]=abs(x[i]-x[j])+c[i]+b[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
nextpos[StartPoint]=EndPoint;
|
||||
LL sum=dis[StartPoint][EndPoint];
|
||||
int GoodTargetPoint=0;
|
||||
for(int PointToView=1;PointToView<=n;PointToView++)
|
||||
{
|
||||
if(PointToView==StartPoint||PointToView==EndPoint) continue;
|
||||
LL MinDis=INF;
|
||||
for(int CurrentPoint=StartPoint;CurrentPoint!=EndPoint;CurrentPoint=nextpos[CurrentPoint])
|
||||
{
|
||||
LL tmp=dis[CurrentPoint][PointToView]+dis[PointToView][nextpos[CurrentPoint]]-dis[CurrentPoint][nextpos[CurrentPoint]];
|
||||
if(tmp<MinDis)
|
||||
{
|
||||
MinDis=tmp;
|
||||
GoodTargetPoint=CurrentPoint;
|
||||
}
|
||||
}
|
||||
sum+=MinDis;
|
||||
nextpos[PointToView]=nextpos[GoodTargetPoint];
|
||||
nextpos[GoodTargetPoint]=PointToView;
|
||||
}
|
||||
printf("%lld\n",sum);
|
||||
return 0;
|
||||
}
|
104
Codeforces/705D_femsub.cpp
Normal file
104
Codeforces/705D_femsub.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
//#include <bits/stdc++.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
using namespace std;
|
||||
long double esp=1e-11;
|
||||
//#pragma comment(linker, "/STACK:1024000000,1024000000")
|
||||
#define fi first
|
||||
#define se second
|
||||
#define all(a) (a).begin(),(a).end()
|
||||
#define cle(a) while(!a.empty())a.pop()
|
||||
#define mem(p,c) memset(p,c,sizeof(p))
|
||||
#define mp(A, B) make_pair(A, B)
|
||||
#define pb push_back
|
||||
#define lson l , m , rt << 1
|
||||
#define rson m + 1 , r , rt << 1 | 1
|
||||
typedef long long int LL;
|
||||
const long double PI = acos((long double)-1);
|
||||
const LL INF=0x3f3f3f3f3f3f3f3fll;
|
||||
const LL MOD =1000000007ll;
|
||||
const int maxn=5001;
|
||||
LL dp[2][maxn][3];
|
||||
LL m[maxn][4];
|
||||
int in[maxn][2],n;
|
||||
void update(int x,int a,int b,LL ans)
|
||||
{
|
||||
if(a==0&&b==0&&x!=n)return;
|
||||
if(a>=0&&b>=0&&(a-b+1)>=0&&(a-b+1)<3)
|
||||
{
|
||||
dp[x&1][a][a-b+1]=min(dp[x&1][a][a-b+1],ans);
|
||||
//printf("****%d %d %d %lld\n",x,a,b,ans);
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
//freopen("in.txt", "r", stdin);
|
||||
//freopen("inlay.in", "r", stdin);
|
||||
//freopen("out.txt", "w", stdout);
|
||||
//::iterator iter; %I64d
|
||||
//for(int x=1;x<=n;x++)
|
||||
//for(int y=1;y<=n;y++)
|
||||
//scanf("%d",&a);
|
||||
//printf("%d\n",ans);
|
||||
int s,e;
|
||||
scanf("%d%d%d",&n,&s,&e);
|
||||
LL t;
|
||||
for(int x=1;x<=n;x++)
|
||||
{
|
||||
scanf("%I64d",&t);
|
||||
m[x][0]=m[x][2]=t;
|
||||
m[x][1]=m[x][3]=-t;
|
||||
in[x][0]=1;
|
||||
in[x][1]=1;
|
||||
}
|
||||
for(int y=0;y<4;y++)
|
||||
for(int x=1;x<=n;x++)
|
||||
{
|
||||
scanf("%I64d",&t);
|
||||
m[x][y]+=t; //printf("%d %d %lld\n",x,y,m[x][y]);
|
||||
}
|
||||
m[s][0]=m[s][1]=0;
|
||||
m[e][2]=m[e][3]=0;
|
||||
in[s][0]=0;
|
||||
in[s][1]=1;
|
||||
in[e][0]=1;
|
||||
in[e][1]=0;
|
||||
memset(dp,0x3f,sizeof(dp));
|
||||
LL a,b;
|
||||
dp[0][0][1]=0;
|
||||
for(int x=1;x<=n;x++)
|
||||
{
|
||||
mem(dp[x&1],0x3f);
|
||||
for(int y=0;y<=n;y++)
|
||||
for(int z=0;z<3;z++)
|
||||
if(dp[(x-1)&1][y][z]!=INF)
|
||||
{
|
||||
a=y;
|
||||
b=a+1-z;
|
||||
if(b<0)continue;
|
||||
//printf("%d %d %d %lld\n",x-1,a,b,dp[(x-1)&1][y][z]);
|
||||
if(a-in[x][1]>=0)
|
||||
update(x,a-in[x][1]+in[x][0],b,dp[(x-1)&1][y][z]+m[x][1]+m[x][2]);
|
||||
if(b-in[x][0]>=0)
|
||||
update(x,a,b-in[x][0]+in[x][1],dp[(x-1)&1][y][z]+m[x][0]+m[x][3]);
|
||||
update(x,a+in[x][0],b+in[x][1],dp[(x-1)&1][y][z]+m[x][1]+m[x][3]);
|
||||
if(a-in[x][1]>=0&&b-in[x][0]>=0)
|
||||
update(x,a-in[x][1],b-in[x][0],dp[(x-1)&1][y][z]+m[x][0]+m[x][2]);
|
||||
}
|
||||
}
|
||||
printf("%I64d\n",dp[n&1][0][1]);
|
||||
return 0;
|
||||
}
|
54
Codeforces/705D_jaihk662.cpp
Normal file
54
Codeforces/705D_jaihk662.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
#include<string.h>
|
||||
typedef struct
|
||||
{
|
||||
__int64 x;
|
||||
__int64 rl, rr, ll, lr;
|
||||
}Point;
|
||||
Point s[5005];
|
||||
__int64 net[5005];
|
||||
__int64 AtoB(Point a, Point b)
|
||||
{
|
||||
if(b.x<a.x)
|
||||
return abs(a.x-b.x)+a.ll+b.rr;
|
||||
return abs(a.x-b.x)+a.lr+b.rl;
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
__int64 n, a, b, i, j, k, temp, sum, best;
|
||||
scanf("%I64d%I64d%I64d", &n, &a, &b);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%I64d", &s[i].x);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%I64d", &s[i].rl);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%I64d", &s[i].rr);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%I64d", &s[i].ll);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%I64d", &s[i].lr);
|
||||
sum = AtoB(s[a], s[b]);
|
||||
net[a] = b;
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
if(i==a || i==b)
|
||||
continue;
|
||||
k = 10000000000000ll;
|
||||
for(j=a;j!=b;j=net[j])
|
||||
{
|
||||
temp = AtoB(s[j], s[i])+AtoB(s[i], s[net[j]])-AtoB(s[j], s[net[j]]);
|
||||
if(temp<k)
|
||||
{
|
||||
k = temp;
|
||||
best = j;
|
||||
}
|
||||
}
|
||||
sum += k;
|
||||
net[i] = net[best];
|
||||
net[best] = i;
|
||||
}
|
||||
printf("%I64d\n", sum);
|
||||
return 0;
|
||||
}
|
4
Codeforces/Readme.md
Normal file
4
Codeforces/Readme.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
#Codeforces
|
||||
> This is a contest Platform.
|
||||
|
||||
[Goto Codeforces Home Page](http://codeforces.com/ "Codeforces")
|
63
HDOJ/1003.cpp
Normal file
63
HDOJ/1003.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
#define MAXN 100005
|
||||
int A[MAXN];
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
scanf("%d",&t);
|
||||
for(int ii=0;ii<t;ii++)
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
int inMAX;
|
||||
int inMAXpos=0;
|
||||
scanf("%d",&inMAX);
|
||||
A[0]=inMAX;
|
||||
for(int i=1;i<n;i++)
|
||||
{
|
||||
scanf("%d",&A[i]);
|
||||
if(A[i]>inMAX)
|
||||
{
|
||||
inMAX=A[i];
|
||||
inMAXpos=i;
|
||||
}
|
||||
}
|
||||
if(inMAX<0)
|
||||
{
|
||||
printf("Case %d:\n%d %d %d\n",ii+1,inMAX,inMAXpos+1,inMAXpos+1);
|
||||
if(t-ii>1) printf("\n");
|
||||
continue;
|
||||
}
|
||||
int sum=A[0];
|
||||
int L=0;
|
||||
int R=0;
|
||||
int maxsum=0;
|
||||
int maxL=0;
|
||||
int maxR=0;
|
||||
for(int i=1;i<n;i++)
|
||||
{
|
||||
if(sum>=0)
|
||||
{
|
||||
sum+=A[i];
|
||||
if(A[i]>0) R=i;
|
||||
}
|
||||
else
|
||||
{
|
||||
sum=A[i];
|
||||
L=R=i;
|
||||
}
|
||||
if(sum>maxsum)
|
||||
{
|
||||
maxsum=sum;
|
||||
maxL=L;
|
||||
maxR=R;
|
||||
}
|
||||
}
|
||||
printf("Case %d:\n%d %d %d\n",ii+1,maxsum,maxL+1,maxR+1);
|
||||
if(t-ii>1) printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
50
HDOJ/1003_XXXX.cpp
Normal file
50
HDOJ/1003_XXXX.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include <cstdio>
|
||||
using namespace std;
|
||||
#define MAXN 100005
|
||||
|
||||
typedef struct{ int s, l, r; }Sum;
|
||||
|
||||
Sum MaxSub(int a[], int n);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ar[MAXN], c, n, i, j;
|
||||
Sum x = {0, 0, 0};
|
||||
scanf("%d", &c);
|
||||
for(i = 1; i <= c; i++)
|
||||
{
|
||||
scanf("%d", &n);
|
||||
for(j = 1; j <= n; j++)
|
||||
scanf("%d", &ar[j]);
|
||||
x = MaxSub(ar, n);
|
||||
printf("Case %d:\n%d %d %d", i,x.s, x.l, x.r);
|
||||
if(i != c) printf("\n\n");
|
||||
else printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Sum MaxSub(int a[], int n)
|
||||
{
|
||||
int i, s = 0, l = 1, r = 1, b;
|
||||
Sum sum = {a[1], 0, 0};
|
||||
for(i = 1; i <= n; i++)
|
||||
{
|
||||
if(s >= 0)
|
||||
{
|
||||
s += a[i];
|
||||
if(a[i] > 0) r = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = a[i];
|
||||
r = l = i;
|
||||
}
|
||||
if(s >= sum.s)
|
||||
{
|
||||
sum.s = s;
|
||||
sum.l = l;
|
||||
sum.r = r;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
40
HDOJ/1003_mtry.cpp
Normal file
40
HDOJ/1003_mtry.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include<iostream>
|
||||
#define N 100010
|
||||
using namespace std;
|
||||
int a[N],d[N];
|
||||
int main()
|
||||
{
|
||||
int test,n,i,max,k,f,e;
|
||||
cin>>test;
|
||||
k=1;
|
||||
while(test--)
|
||||
{
|
||||
cin>>n;
|
||||
for(i=1;i<=n;i++)
|
||||
cin>>a[i];
|
||||
d[1]=a[1];
|
||||
for(i=2;i<=n;i++)
|
||||
{
|
||||
if(d[i-1]<0) d[i]=a[i];
|
||||
else d[i]=d[i-1]+a[i];
|
||||
}
|
||||
max=d[1];e=1;
|
||||
for(i=2;i<=n;i++)
|
||||
{
|
||||
if(max<d[i])
|
||||
{
|
||||
max=d[i];e=i;
|
||||
}
|
||||
}
|
||||
int t=0;
|
||||
f=e;
|
||||
for(i=e;i>0;i--)
|
||||
{
|
||||
t=t+a[i];
|
||||
if(t==max) f=i;
|
||||
}
|
||||
cout<<"Case "<<k++<<":"<<endl<<max<<" "<<f<<" "<<e<<endl;
|
||||
if(test) cout<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/// TLE -> WA
|
||||
/// TLE -> WA -> AC
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
|
36
HDOJ/1028.cpp
Normal file
36
HDOJ/1028.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
#define MAXN 128
|
||||
|
||||
int c[MAXN];
|
||||
int d[MAXN];
|
||||
|
||||
int main()
|
||||
{
|
||||
int N;
|
||||
while(cin>>N)
|
||||
{
|
||||
for(int i=0;i<=N;i++)
|
||||
{
|
||||
c[i]=1;
|
||||
d[i]=0;
|
||||
}
|
||||
for(int i=2;i<=N;i++)
|
||||
{
|
||||
for(int j=0;j<=N;j++)
|
||||
{
|
||||
for(int k=0;k+j<=N;k+=i)
|
||||
{
|
||||
d[j+k] += c[j];
|
||||
}
|
||||
}
|
||||
for(int j=0;j<=N; ++j)
|
||||
{
|
||||
c[j] = d[j];
|
||||
d[j] = 0;
|
||||
}
|
||||
}
|
||||
cout<<c[N]<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
31
HDOJ/1029.cpp
Normal file
31
HDOJ/1029.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
while(scanf("%d",&n)==1)
|
||||
{
|
||||
int target=(n+1)/2;
|
||||
int tmp,ans;
|
||||
map<int,int> p;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&tmp);
|
||||
p[tmp]++;
|
||||
}
|
||||
for(map<int,int>::iterator iter=p.begin();iter!=p.end();iter++)
|
||||
{
|
||||
if(iter->second >=target)
|
||||
{
|
||||
ans=iter->first;
|
||||
}
|
||||
}
|
||||
printf("%d\n",ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
67
HDOJ/1080.cpp
Normal file
67
HDOJ/1080.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
char stra[128];
|
||||
char strb[128];
|
||||
#define MAXL 105
|
||||
int dp[MAXL][MAXL];
|
||||
int label(char c)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'A': return 0;
|
||||
case 'C': return 1;
|
||||
case 'G': return 2;
|
||||
case 'T': return 3;
|
||||
case '-': return 4;
|
||||
default: return 4;/// Here if c=='\0' , we should regard it as a '-';
|
||||
}
|
||||
}
|
||||
int trans[5][5]=
|
||||
{
|
||||
{
|
||||
5,-1,-2,-1,-3
|
||||
},
|
||||
{
|
||||
-1,5,-3,-2,-4
|
||||
},
|
||||
{
|
||||
-2,-3,5,-2,-2
|
||||
},
|
||||
{
|
||||
-1,-2,-2,5,-1
|
||||
},
|
||||
{
|
||||
-3,-4,-2,-1,0
|
||||
}
|
||||
};
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
scanf("%d",&t);
|
||||
while(t--)
|
||||
{
|
||||
int a,b;
|
||||
scanf("%d %s %d %s",&a,stra+1,&b,strb+1);
|
||||
memset(dp,0,sizeof(int)*MAXL*MAXL);
|
||||
/// Init this dp array (Why?)
|
||||
int n=max(a,b);
|
||||
for(int ci=1;ci<=n;ci++)
|
||||
{
|
||||
dp[0][ci]=dp[0][ci-1]+trans[label('-')][label(strb[ci])];
|
||||
dp[ci][0]=dp[ci-1][0]+trans[label(stra[ci])][label('-')];
|
||||
}
|
||||
|
||||
for(int i=1;i<=a;i++)
|
||||
{
|
||||
for(int j=1;j<=b;j++)
|
||||
{
|
||||
dp[i][j]=max(max(dp[i-1][j]+trans[label(stra[i])][label('-')],dp[i][j-1]+trans[label('-')][label(strb[j])]),dp[i-1][j-1]+trans[label(stra[i])][label(strb[j])]);
|
||||
}
|
||||
}
|
||||
printf("%d\n",dp[a][b]);
|
||||
}
|
||||
return 0;
|
||||
}
|
106
HDOJ/1081.cpp
Normal file
106
HDOJ/1081.cpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
#define MAXN 128
|
||||
|
||||
typedef int ARRAY[MAXN][MAXN];
|
||||
|
||||
ARRAY pool;
|
||||
|
||||
#define INF 0x3f3f3f3f
|
||||
#define NINF -INF-1
|
||||
/*
|
||||
int MaxSum(int N,int* a)
|
||||
{
|
||||
int sum=0;
|
||||
int tmp=0;
|
||||
for(int i=0;i<N;i++)
|
||||
{
|
||||
if(tmp>0)
|
||||
{
|
||||
tmp+=a[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp=a[i];
|
||||
}
|
||||
if(tmp>sum)
|
||||
{
|
||||
sum=tmp;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
//*/
|
||||
int MaxSum(int n,int *a)
|
||||
{
|
||||
int sum=NINF,b=0;
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
if(b>0)
|
||||
{
|
||||
b+=a[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
b=a[i];
|
||||
}
|
||||
if(b>sum)
|
||||
{
|
||||
sum = b;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
int MaxSumRect(int m,int n,ARRAY& a)
|
||||
{
|
||||
int sum = NINF;
|
||||
int* b = new int[n+1];
|
||||
for(int i=0; i<m; i++)//枚举行
|
||||
{
|
||||
memset(b,0,sizeof(int)*(n+1));
|
||||
|
||||
for(int j=i; j<m; j++) //枚举初始行i,结束行j
|
||||
{
|
||||
for(int k=0; k<n; k++)
|
||||
{
|
||||
b[k] += a[j][k];//b[k]为纵向列之和
|
||||
}
|
||||
int max = MaxSum(n,b);
|
||||
if(max>sum)
|
||||
{
|
||||
sum = max;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
delete[] b;
|
||||
return sum;
|
||||
}
|
||||
|
||||
int MaxSumSquare(int N,ARRAY& a)
|
||||
{
|
||||
return MaxSumRect(N,N,a);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
while(scanf("%d",&n)!=EOF)
|
||||
{
|
||||
memset(pool,0,sizeof(pool));
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
for(int j=0; j<n; j++)
|
||||
{
|
||||
scanf("%d",&pool[i][j]);
|
||||
}
|
||||
}
|
||||
int ans=MaxSumSquare(n,pool);
|
||||
printf("%d\n",ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
69
HDOJ/1231.cpp
Normal file
69
HDOJ/1231.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
#define MAXL 10240
|
||||
int a[MAXL];
|
||||
typedef struct
|
||||
{
|
||||
int result,start,ends;
|
||||
}PACK;
|
||||
PACK MaxSum(int N)
|
||||
{
|
||||
int sum=-1;
|
||||
int tmp=0;
|
||||
int start=0;
|
||||
int ends=0;
|
||||
int tmpstart=0;
|
||||
int tmpends=0;
|
||||
for(int i=0;i<N;i++)
|
||||
{
|
||||
if(tmp>0)
|
||||
{
|
||||
tmp+=a[i];
|
||||
tmpends=i;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp=a[i];
|
||||
tmpstart=i;
|
||||
}
|
||||
if(tmp>sum)
|
||||
{
|
||||
sum=tmp;
|
||||
start=tmpstart;
|
||||
ends=tmpends;
|
||||
}
|
||||
}
|
||||
if(ends<start)
|
||||
{
|
||||
ends=start;
|
||||
}
|
||||
PACK c;
|
||||
c.result=sum;
|
||||
c.start=start;
|
||||
c.ends=ends;
|
||||
return c;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
while(scanf("%d",&t)==1&&t!=0)
|
||||
{
|
||||
bool check=true;
|
||||
for(int i=0;i<t;i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
if(check&&a[i]>=0) check=false;
|
||||
}
|
||||
if(check)
|
||||
{
|
||||
printf("0 %d %d\n",a[0],a[t-1]);
|
||||
continue;
|
||||
}
|
||||
PACK c=MaxSum(t);
|
||||
printf("%d %d %d\n",c.result,a[c.start],a[c.ends]);
|
||||
}
|
||||
return 0;
|
||||
}
|
84
HDOJ/1404_qiqijianglu.cpp
Normal file
84
HDOJ/1404_qiqijianglu.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
HDU 1404
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<math.h>
|
||||
#include<iostream>
|
||||
#include<string.h>
|
||||
using namespace std;
|
||||
|
||||
const int MAXN=1000000;
|
||||
int sg[MAXN];
|
||||
int get_length(int n)//得到整数n的位数
|
||||
{
|
||||
if(n/100000) return 6;
|
||||
if(n/10000) return 5;
|
||||
if(n/1000) return 4;
|
||||
if(n/100) return 3;
|
||||
if(n/10) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _extend(int n)//sg[n]=0;表示n为后者必胜
|
||||
//那么所以可以一步变成n的都是前者必胜
|
||||
{
|
||||
int len=get_length(n);
|
||||
int i;
|
||||
for(i=len;i>=1;i--)//每一个位上加上一个数
|
||||
{
|
||||
int m=n;
|
||||
int base=1;
|
||||
for(int j=1;j<i;j++) base*=10;
|
||||
int tmp=(m%(base*10))/base;
|
||||
for(int j=tmp;j<9;j++)
|
||||
{
|
||||
m+=base;
|
||||
sg[m]=1;//m为前者必胜点
|
||||
}
|
||||
}
|
||||
if(len!=6)//长度小于6,则可以在后面加0开头的
|
||||
{
|
||||
int m=n;
|
||||
int base=1;
|
||||
for(int i=len;i<6;i++)
|
||||
{
|
||||
m*=10;
|
||||
for(int b=0;b<base;b++)
|
||||
sg[m+b]=1;
|
||||
base*=10;
|
||||
}
|
||||
}
|
||||
}
|
||||
void fun()
|
||||
{
|
||||
memset(sg,0,sizeof(sg));
|
||||
sg[0]=1;
|
||||
for(int i=1;i<MAXN;i++)
|
||||
{
|
||||
if(!sg[i]) _extend(i);
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
char str[8];
|
||||
int n;
|
||||
fun();
|
||||
while(scanf("%s",&str)!=EOF)
|
||||
{
|
||||
if(str[0]=='0') //第一个数字是0,则前者必胜
|
||||
{
|
||||
printf("Yes\n");
|
||||
continue;
|
||||
}
|
||||
int len=strlen(str);//第一个数字非0,再转化成整型数
|
||||
n=0;
|
||||
for(int i=0;i<len;i++)
|
||||
{
|
||||
n*=10;
|
||||
n+=str[i]-'0';
|
||||
}
|
||||
if(sg[n]) printf("Yes\n");
|
||||
else printf("No\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
55
HDOJ/2089.cpp
Normal file
55
HDOJ/2089.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
#define MAXLEN 10
|
||||
#define MAXNUM 10
|
||||
int dp[MAXLEN][MAXNUM];
|
||||
int num[MAXLEN];
|
||||
char _tmpbuff[MAXLEN];
|
||||
|
||||
inline int Deal(int N)
|
||||
{
|
||||
sprintf(_tmpbuff,"%d",N);
|
||||
int _len=strlen(_tmpbuff);
|
||||
/// num: 低位存放数字低位(逆序)
|
||||
for(int i=0; i<_len; i++)
|
||||
{
|
||||
num[i]=_tmpbuff[_len-i-1]-'0';
|
||||
}
|
||||
num[_len]=0;
|
||||
int ans=0;
|
||||
for(int i=_len-1; i>=0; i--)
|
||||
{
|
||||
for(int j=0; j<num[i]; j++)
|
||||
{
|
||||
if(num[i+1]==6&&j==2) continue;
|
||||
ans+=dp[i+1][j];///重要 i+1
|
||||
}
|
||||
/// ?
|
||||
if (num[i] == 4 || (num[i + 1] == 6 && num[i] == 2)) break;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
dp[0][0] = 1;
|
||||
for (int i = 1; i < MAXLEN; ++i)
|
||||
for (int j = 0; j < MAXNUM; ++j)
|
||||
for (int k = 0; k < MAXNUM; ++k)
|
||||
if (j != 4 && !(j == 6 && k == 2))
|
||||
dp[i][j] += dp[i - 1][k];
|
||||
int n,m;
|
||||
while(scanf("%d %d",&n,&m)==2&&!(n==0&&m==0))
|
||||
{
|
||||
/// Calculate M
|
||||
|
||||
int ans_m=Deal(m+1);
|
||||
int ans_n=Deal(n);
|
||||
|
||||
printf("%d\n",ans_m-ans_n);
|
||||
}
|
||||
return 0;
|
||||
}
|
84
HDOJ/2680.cpp
Normal file
84
HDOJ/2680.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
#define MAXN 1000
|
||||
#define INF 0x3f3f3f3f
|
||||
int mp[MAXN][MAXN];
|
||||
int dis[MAXN];
|
||||
bool vis[MAXN];
|
||||
int n,m,s;
|
||||
void dij(int from)
|
||||
{
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
vis[i]=false;
|
||||
dis[i]=mp[from][i];
|
||||
}
|
||||
vis[from]=1;
|
||||
for(int i=2;i<=n;i++)
|
||||
{
|
||||
int next=i;
|
||||
int minnext=INF;
|
||||
for(int j=1;j<=n;j++)
|
||||
{
|
||||
if(!vis[j]&&minnext>dis[j])
|
||||
{
|
||||
next=j;
|
||||
minnext=dis[j];
|
||||
}
|
||||
}
|
||||
vis[next]=true;
|
||||
for(int j=1;j<=n;j++)
|
||||
{
|
||||
if(!vis[j]&&dis[j]>dis[next]+mp[next][j])
|
||||
{
|
||||
dis[j]=dis[next]+mp[next][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
// queue<int> bus;
|
||||
// bus.push(from);
|
||||
// dis[from]=0;
|
||||
// while(!bus.empty())
|
||||
// {
|
||||
// int pos=bus.front();
|
||||
// bus.pop();
|
||||
// vis[pos]=true;
|
||||
// for(int i=1;i<=n;i++)
|
||||
// {
|
||||
// if(mp[pos][i]!=INF&&!vis[i])
|
||||
// {
|
||||
// dis[i]=min(dis[i],dis[pos]+mp[pos][i]);
|
||||
// bus.push(i);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
int main()
|
||||
{
|
||||
while(scanf("%d %d %d",&n,&m,&s)==3)
|
||||
{
|
||||
memset(mp,0x3f,sizeof(int)*MAXN*MAXN);
|
||||
for(int i=0; i<m; i++)
|
||||
{
|
||||
int u,v,w;
|
||||
scanf("%d %d %d",&u,&v,&w);
|
||||
if(mp[v][u]>w) mp[v][u]=w;
|
||||
}
|
||||
dij(s);
|
||||
int w;
|
||||
scanf("%d",&w);
|
||||
int mindis=INF;
|
||||
for(int i=0;i<w;i++)
|
||||
{
|
||||
int tfrom;
|
||||
scanf("%d",&tfrom);
|
||||
mindis=min(mindis,dis[tfrom]);
|
||||
}
|
||||
if(mindis==INF) printf("-1\n");
|
||||
else printf("%d\n",mindis);
|
||||
}
|
||||
return 0;
|
||||
}
|
77
HDOJ/3555_UESTC_Sayakiss.cpp
Normal file
77
HDOJ/3555_UESTC_Sayakiss.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include<cstdio>
|
||||
#include<cmath>
|
||||
unsigned long long n,ans,sa,nn,np,t,f,i,c[30][30],k,f49;
|
||||
int fbreak,tcase;
|
||||
void cc()
|
||||
{
|
||||
int i,j;
|
||||
c[0][0]=1;
|
||||
c[1][0]=1;c[1][1]=1;
|
||||
for (i=0;i<25;i++)
|
||||
{
|
||||
c[i][0]=1;
|
||||
for (j=1;j<=i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1];
|
||||
}
|
||||
}
|
||||
unsigned long long sayacal(long long n,int k)//10^n
|
||||
{
|
||||
unsigned long long ans;
|
||||
sa=1;f=1;ans=0;
|
||||
while (1)
|
||||
{
|
||||
sa++;k=k-2;n=n/100;if (n==0) break;
|
||||
if (f)
|
||||
{
|
||||
ans=ans+c[sa+k-1][k]*n;
|
||||
f=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ans=ans-c[sa+k-1][k]*n;
|
||||
f=1;
|
||||
}
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cc();//计算组合数
|
||||
scanf("%d",&tcase);
|
||||
while(tcase--)
|
||||
{
|
||||
scanf("%I64d",&n);
|
||||
if (n<49) {printf("0n");continue;}
|
||||
ans=0;fbreak=0;
|
||||
while (n)
|
||||
{
|
||||
k=0;nn=1;
|
||||
while(nn<n)
|
||||
{
|
||||
nn=nn*10;
|
||||
k++;
|
||||
}
|
||||
if (nn!=n) {nn=nn/10;k--;}
|
||||
np=nn;unsigned nnp=0;
|
||||
while (np<=n)
|
||||
{
|
||||
if (nnp!=4) ans+=sayacal(nn,k);
|
||||
else
|
||||
{
|
||||
ans+=nn/10+sayacal(nn,k);
|
||||
ans-=sayacal(nn/10,k-1);
|
||||
}
|
||||
np+=nn;
|
||||
nnp++;
|
||||
if (nnp==4) f49=1; else f49=0;
|
||||
}
|
||||
n=n%nn;nn=nn/10;if (fbreak) break;
|
||||
if (nn) if (f49) if ((n/nn)>8)
|
||||
{
|
||||
ans+=n%nn+1;
|
||||
fbreak=1;
|
||||
}
|
||||
}
|
||||
printf("%I64dn",ans);
|
||||
}
|
||||
}
|
35
HDOJ/3652_kg20006.cpp
Normal file
35
HDOJ/3652_kg20006.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include<bits/stdc++.h>
|
||||
#define ll long long int
|
||||
using namespace std;
|
||||
ll num[30];
|
||||
ll dp[30][15][5];
|
||||
ll dfs(int pos, int mod, int st, bool f){
|
||||
if(pos < 1) return st == 2 && mod == 0;
|
||||
if(!f && dp[pos][mod][st] != -1) return dp[pos][mod][st];
|
||||
int end = f? num[pos] : 9;
|
||||
ll res = 0;
|
||||
for(int i = 0; i <= end; ++i){
|
||||
int nmod = (mod*10 + i) %13;
|
||||
bool nf = (f && i == end);
|
||||
if(st == 2 || (st == 1 && i == 3)) res += dfs(pos-1, nmod, 2, nf);
|
||||
else if(i == 1) res += dfs(pos-1, nmod, 1, nf);
|
||||
else res += dfs(pos-1, nmod, 0, nf);
|
||||
}
|
||||
if(!f) dp[pos][mod][st] = res;
|
||||
return res;
|
||||
}
|
||||
ll solve(ll n){
|
||||
int len = 0;
|
||||
while(n){
|
||||
num[++len] = n%10;
|
||||
n /= 10;
|
||||
}
|
||||
return dfs(len, 0, 0, 1);
|
||||
}
|
||||
int main(){
|
||||
ll n;
|
||||
while(scanf("%lld", &n) != EOF){
|
||||
memset(dp, -1, sizeof(dp));
|
||||
printf("%lld\n", solve(n));
|
||||
}
|
||||
}
|
97
HDOJ/4826.cpp
Normal file
97
HDOJ/4826.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
#define MAXN 205
|
||||
|
||||
/** == ACM Templates == BEGIN */
|
||||
#define INF 0x3f3f3f3f
|
||||
#define NINF 0xc0c0c0c0
|
||||
/** == ACM Templates == END */
|
||||
|
||||
int dpa[MAXN][MAXN];
|
||||
int dpb[MAXN][MAXN];
|
||||
int G[MAXN][MAXN];
|
||||
int ans;
|
||||
int m,n;
|
||||
|
||||
void newinstance()
|
||||
{
|
||||
memset(G,0,sizeof(int)*MAXN*MAXN);
|
||||
scanf("%d %d",&m,&n);
|
||||
for(int i=1;i<=m;i++)
|
||||
{
|
||||
for(int j=1;j<=n;j++)
|
||||
{
|
||||
scanf("%d",&G[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
void solve()
|
||||
{
|
||||
memset(dpa,0xc0,sizeof(int)*MAXN*MAXN);
|
||||
memset(dpb,0xc0,sizeof(int)*MAXN*MAXN);
|
||||
/// Initial Money
|
||||
dpa[0][1]=0;
|
||||
/// Must move from up to down in 1st col.
|
||||
for(int i=1;i<=m;i++)
|
||||
{
|
||||
dpa[i][1]=dpa[i-1][1]+G[i][1];
|
||||
}
|
||||
/// From Col 2, Mr.Dudu can move from up to down or from down to up.
|
||||
/// But the move from right to left is not allowed.
|
||||
for(int j=2;j<=n;j++)
|
||||
{
|
||||
/// From Up to Down, Accepted Move: From left, from up
|
||||
for(int i=1;i<=m;i++)
|
||||
{
|
||||
dpa[i][j]=max(max(dpa[i][j-1],dpb[i][j-1]),dpa[i-1][j])+G[i][j];
|
||||
}
|
||||
/// From down to up, Accepted Move: From Left, from down.
|
||||
for(int i=m;i>=1;i--)
|
||||
{
|
||||
dpb[i][j]=max(max(dpa[i][j-1],dpb[i][j-1]),dpb[i+1][j])+G[i][j];
|
||||
}
|
||||
}
|
||||
ans=max(dpa[1][n],dpb[1][n]);
|
||||
}
|
||||
/*
|
||||
void printDP()
|
||||
{
|
||||
printf("DP:A\n");
|
||||
for(int i=1;i<=m;i++)
|
||||
{
|
||||
for(int j=1;j<=n;j++)
|
||||
{
|
||||
printf("%3d ",dpa[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("DP:B\n");
|
||||
for(int i=1;i<=m;i++)
|
||||
{
|
||||
for(int j=1;j<=n;j++)
|
||||
{
|
||||
printf("%3d ",dpb[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
//*/
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
scanf("%d",&t);
|
||||
for(int i=1;i<=t;i++)
|
||||
{
|
||||
newinstance();
|
||||
solve();
|
||||
//printDP();
|
||||
printf("Case #%d:\n%d\n",i,ans);
|
||||
}
|
||||
return 0;
|
||||
//*/
|
||||
}
|
4
HOJ/Readme.md
Normal file
4
HOJ/Readme.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# 哈尔滨工业大学(哈工大) HOJ
|
||||
[Goto HOJ HomePage](http://acm.hit.edu.cn/hoj/problem/volume "Problem Set")
|
||||
UserName: cc5d6b11c9636cfaf74c1fb6892c1e6d
|
||||
Password: 7b742197d58b7fcad9674695bd8d615f
|
8
LuoGu/1001.c
Normal file
8
LuoGu/1001.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
int a, b;
|
||||
scanf("%d %d", &a, &b);
|
||||
printf("%d", a + b);
|
||||
return 0;
|
||||
}
|
3
LuoGu/Readme.md
Normal file
3
LuoGu/Readme.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
#洛谷 LuoGu
|
||||
[Goto Home Page](http://www.luogu.org/ "Welcome to LuoGu")
|
||||
[Help LuoGu out](http://www.luogu.org/discuss/show?postid=2376 "Help LuoGu out")
|
80
NBUTOJ/1667_wyg1997.cpp
Normal file
80
NBUTOJ/1667_wyg1997.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
struct node
|
||||
{
|
||||
int from,to;
|
||||
int l;
|
||||
}data[100011];
|
||||
int main()
|
||||
{
|
||||
int u;
|
||||
int n;
|
||||
int num;
|
||||
int a[100011];
|
||||
int ans;
|
||||
scanf ("%d",&u);
|
||||
while (u--)
|
||||
{
|
||||
scanf ("%d",&n);
|
||||
for (int i = 1 ; i <= n ; i++)
|
||||
scanf ("%d",&a[i]);
|
||||
num = 1;
|
||||
ans = 1;
|
||||
data[num].from = 1;
|
||||
data[num].l = 1;
|
||||
for (int i = 2 ; i <= n ; i++)
|
||||
{
|
||||
if (a[i] > a[i-1])
|
||||
{
|
||||
data[num].l++;
|
||||
data[num].to = i;
|
||||
ans = max (ans,data[num].l);
|
||||
}
|
||||
else
|
||||
{
|
||||
num++;
|
||||
data[num].from = i;
|
||||
data[num].to = i;
|
||||
data[num].l = 1;
|
||||
}
|
||||
}
|
||||
if (ans == n || ans == n-1) //特判一下
|
||||
{
|
||||
printf ("%d\n",n);
|
||||
continue;
|
||||
}
|
||||
// if (ans == n - 1) //题目不清晰,不知道是否可以把该数改为负数
|
||||
// {
|
||||
// if ((a[1] < a[2]) || (a[1] >= a[2] && a[2] != 0))
|
||||
// printf ("%d\n",n);
|
||||
// else
|
||||
// printf ("%d\n",ans);
|
||||
// continue;
|
||||
// }
|
||||
ans++;
|
||||
for (int i = 1 ; i < num ; i++)
|
||||
{
|
||||
if (data[i+1].l == 1 || data[i].l == 1) //子串长度为1挺麻烦的,单独处理下
|
||||
{
|
||||
ans = max (ans , data[i+1].l + 1);
|
||||
ans = max (ans , data[i].l + 1);
|
||||
if (data[i+1].l == 1 && i != num-1)
|
||||
{
|
||||
if (a[data[i+1].to-1] + 1 < a[data[i+2].from])
|
||||
ans = max (ans , data[i].l + data[i+2].l + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (a[data[i].to-1] + 1 < a[data[i+1].from]) //修改前一个子串的最后一个数
|
||||
ans = max (ans , data[i].l + data[i+1].l);
|
||||
if (a[data[i+1].from-1] + 1 < a[data[i+1].from+1]) //修改后一个子串的第一个数
|
||||
ans = max (ans , data[i].l + data[i+1].l);
|
||||
}
|
||||
}
|
||||
printf ("%d\n",ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
2
NBUTOJ/Readme.md
Normal file
2
NBUTOJ/Readme.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
#NingBo University of Technology 宁波工程学院
|
||||
[Goto Home Page](https://ac.2333.moe/ "NBUT Online Judge :: Index")
|
83
NYOJ/737.cpp
Normal file
83
NYOJ/737.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/**石子合并*/
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#define dprintf(format,args...)
|
||||
|
||||
const int INF = 0x3f3f3f3f;
|
||||
const int NINF = -INF -1;
|
||||
|
||||
#define MAXN 10000
|
||||
|
||||
/**
|
||||
inline void show(vector<int>& s)
|
||||
{
|
||||
printf("Stone: ");
|
||||
for(auto& i:s)
|
||||
{
|
||||
printf("%d ",i);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
//*/
|
||||
|
||||
#define show(s)
|
||||
|
||||
void solve(int n)
|
||||
{
|
||||
vector<int> stone;
|
||||
stone.push_back(INF);
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
int tmp;
|
||||
scanf("%d",&tmp);
|
||||
stone.push_back(tmp);
|
||||
}
|
||||
stone.push_back(INF);
|
||||
|
||||
dprintf("Init:\n");show(stone);
|
||||
|
||||
int sum=0;
|
||||
while(stone.size()>3)
|
||||
{
|
||||
int k;
|
||||
for(k=1;k<stone.size()-1;k++)
|
||||
{
|
||||
if(stone[k-1]<=stone[k+1])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dprintf("Before deletion :\n");show(stone);
|
||||
|
||||
int tmp=stone[k-1]+stone[k];
|
||||
sum+=tmp;
|
||||
k--;
|
||||
stone.erase(stone.begin()+k);
|
||||
stone.erase(stone.begin()+k);
|
||||
|
||||
dprintf("After deletion: \n");show(stone);
|
||||
|
||||
for(int i=k-1;i>=0;i--)
|
||||
{
|
||||
if(stone[i]>=tmp)
|
||||
{
|
||||
stone.insert(stone.begin()+i+1,tmp);
|
||||
dprintf("After Insertion :\n");show(stone);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d\n",sum);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
while(scanf("%d",&n)==1&&n!=0) solve(n);
|
||||
return 0;
|
||||
}
|
2
OpenJudge/Readme.md
Normal file
2
OpenJudge/Readme.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
#POJ - OpenJudge
|
||||
[Goto Home Page](http://noi.openjudge.cn/ "Welcome to OpenJudge - POJ")
|
3
OpenJudge/ch0101_冰封/01.pas
Normal file
3
OpenJudge/ch0101_冰封/01.pas
Normal file
|
@ -0,0 +1,3 @@
|
|||
begin
|
||||
writeln('Hello, World!');
|
||||
end.
|
5
OpenJudge/ch0101_冰封/02.pas
Normal file
5
OpenJudge/ch0101_冰封/02.pas
Normal file
|
@ -0,0 +1,5 @@
|
|||
var a, b, c:longint;
|
||||
begin
|
||||
readln(a, b, c);
|
||||
writeln(b);
|
||||
end.
|
24
OpenJudge/ch0101_冰封/10.pas
Normal file
24
OpenJudge/ch0101_冰封/10.pas
Normal file
|
@ -0,0 +1,24 @@
|
|||
begin
|
||||
writeln(' ********');
|
||||
writeln(' ************');
|
||||
writeln(' ####....#.');
|
||||
writeln(' #..###.....##....');
|
||||
writeln(' ###.......###### ### ### ### ###');
|
||||
writeln(' ........... #...# #...# #...# #...#');
|
||||
writeln(' ##*####### #.#.# #.#.# #.#.# #.#.#');
|
||||
writeln(' ####*******###### #.#.# #.#.# #.#.# #.#.#');
|
||||
writeln(' ...#***.****.*###.... #...# #...# #...# #...#');
|
||||
writeln(' ....**********##..... ### ### ### ###');
|
||||
writeln(' ....**** *****....');
|
||||
writeln(' #### ####');
|
||||
writeln(' ###### ######');
|
||||
writeln('############################################################## ##################################');
|
||||
writeln('#...#......#.##...#......#.##...#......#.##------------------# #...#......#.##------------------#');
|
||||
writeln('###########################################------------------# ###############------------------#');
|
||||
writeln('#..#....#....##..#....#....##..#....#....##################### #..#....#....#####################');
|
||||
writeln('########################################## #----------# ############## #----------#');
|
||||
writeln('#.....#......##.....#......##.....#......# #----------# #.....#......# #----------#');
|
||||
writeln('########################################## #----------# ############## #----------#');
|
||||
writeln('#.#..#....#..##.#..#....#..##.#..#....#..# #----------# #.#..#....#..# #----------#');
|
||||
writeln('########################################## ############ ############## ############');
|
||||
end.
|
26
OpenJudge/ch0105_冰封/15.c
Normal file
26
OpenJudge/ch0105_冰封/15.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include<stdio.h>
|
||||
|
||||
int a,i,m,n;
|
||||
int b[20],cmin,cmax;
|
||||
|
||||
int main(void){
|
||||
int cc = 0;
|
||||
scanf("%d",&a);
|
||||
scanf("%d %d",&m,&n);
|
||||
cc = (n*1000)/m;
|
||||
cmax = cc + 50;
|
||||
cmin = cc - 50;
|
||||
for(i = 0; i < a-1; i++){
|
||||
scanf("%d %d",&m,&n);
|
||||
b[i] = (n*1000)/m;
|
||||
}
|
||||
|
||||
for(i = 0; i < a-1; i++){
|
||||
if(b[i] > cmax) printf("better\n");
|
||||
else if(b[i] < cmin) printf("worse\n");
|
||||
else printf("same\n");
|
||||
}
|
||||
|
||||
// getchar();getchar();getchar();getchar();getchar();getchar();getchar();
|
||||
return 0;
|
||||
}
|
21
OpenJudge/ch0105_冰封/37.c
Normal file
21
OpenJudge/ch0105_冰封/37.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
int main(void){
|
||||
int a,b,c;
|
||||
int i,j;
|
||||
char d;
|
||||
scanf("%d %d %c %d",&a,&b,&d,&c);
|
||||
for(i = 0;i < a;i++){
|
||||
for(j = 0;j < b;j++){
|
||||
if((c == 1)||(i == 0)||(i == a-1)||(j == 0)||(j == b-1)){
|
||||
putchar(d);
|
||||
}
|
||||
else{
|
||||
putchar(' ');
|
||||
}
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
// system("pause");
|
||||
return 0;
|
||||
}
|
13
OpenJudge/ch0105_冰封/38.c
Normal file
13
OpenJudge/ch0105_冰封/38.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include<stdio.h>
|
||||
|
||||
int main(int argc,char** argv){
|
||||
int i,j;
|
||||
scanf("%d",&i);
|
||||
for(j = 2; j < i/2; j++ ){
|
||||
if(i%j == 0){
|
||||
printf("%d",i/j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
18
OpenJudge/ch0105_冰封/40.cpp
Normal file
18
OpenJudge/ch0105_冰封/40.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
int main(){
|
||||
int n,i,j;
|
||||
scanf("%d", &n);
|
||||
int ans = 0, count=0;
|
||||
i=1;
|
||||
for(i=1;i<=n;i++){
|
||||
for(j=1;j<=i;j++){
|
||||
ans+=i;
|
||||
count++;
|
||||
if(count==n){
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
13
OpenJudge/ch0106_冰封/01.c
Normal file
13
OpenJudge/ch0106_冰封/01.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int a[1000], n, i, cnt = 0, std;
|
||||
scanf("%i", &n);
|
||||
for(i = 0; i < n; i++)
|
||||
scanf("%i", &a[i]);
|
||||
scanf("%i", &std);
|
||||
for(i = 0; i < n; i++)
|
||||
if(a[i] == std) cnt++;
|
||||
printf("%i", cnt);
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user