Codes included

This commit is contained in:
unknown 2016-07-06 14:10:50 +08:00
parent ec1dee204d
commit d3632b4ff5
3 changed files with 183 additions and 0 deletions

42
CWOJ/1193_冰封.cpp Normal file
View 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
View 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
View 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;
}