Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

刘昕level1 #56

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
64 changes: 64 additions & 0 deletions liuxin/liuxinclevel1/c++.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdio.h>
#include <string.h>
typedef long long LL;
const int MAXN=100005;
char s[MAXN];
LL m,n,p,q,e1,e2,a[MAXN];
LL mul(LL a,LL b,LL c){
LL ans=0; a%=c;
while (b){
if (b&1) {
ans=ans+a;
if (ans>=c) ans-=c;
}
a=a+a; b>>=1;
if (a>=c) a-=c;
}
return ans;
}
LL power(LL a,LL b,LL c){
LL ans=1;
while (b){
if (b&1) ans=mul(ans,a,c);
a=mul(a,a,c); b>>=1;
}
return ans;
}
LL next_prime(LL x) {
int i,j;
while (1) {
for (i=2,j=1;i*i<=x;++i) if (x%i==0) { j=0; break; }
if (j==1) { return x; break; }
x++;
}
}
LL gcd(LL x,LL y){ return y==0?x:gcd(y,x%y); }
LL extend_gcd(LL a,LL b,LL &x,LL &y) {
if (b==0) { x=1; y=0; return a; }
else {
int tmp=extend_gcd(b,a%b,y,x);
y-=x*(a/b); return tmp;
}
}
void test(){
p=next_prime(102567192LL);
q=next_prime(186127350LL);
n=p*q;
printf("%lld %lld %lld\n",p,q,n);
for (LL i=10;i;++i) if (gcd(i,(p-1)*(q-1))==1) { e1=i; break; }
extend_gcd(e1,(p-1)*(q-1),e2,m);
e2=(e2%((p-1)*(q-1))+(p-1)*(q-1))%((p-1)*(q-1));
printf("%lld %lld\n",e1,e2);
}
//102567211 186127387 19090566975307657 11 17355060624193691
int main(){
int i; //test();
p=102567211LL; q=186127387LL; n=19090566975307657LL; e1=11LL; e2=17355060624193691LL;
while (scanf("%s",s)!=EOF) {
m=strlen(s);
for (i=0;i<m;i++) printf("%lld ",a[i]=power(s[i],e1,n)); printf("\n");
//for (i=0;i<m;++i) printf("%c",power(a[i],e2,n)); printf("\n");
}

return 0;
}
29 changes: 29 additions & 0 deletions liuxin/liuxinclevel1/p01_runningLetter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <windows.h>
int main(){
int i,j=0,k=1;
while (1) {
system("cls");
for (i=1;i<=j;++i) {
putchar(' ');
}
printf("R\n");
Sleep(100);
if (k) {
j++;
}else{
j--;
}
if (j==79) {
k=0;
}
else if (j==0) {
k=1;
}
}
return 0;
}

/*
Ugly format
*/
20 changes: 20 additions & 0 deletions liuxin/liuxinclevel1/p02_isPrime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <math.h>
#include <stdio.h>
int main(){
int n,i,j;
scanf("%d",&n);
for (i=2,j=1;i<=trunc(sqrt(n));++i)
if (n%i==0) {
j=0; break;
}
if (j&&n!=1) {
printf("YES\n");
}else{
printf("NO\n");
}
return 0;
}

/*
Ugly format
*/
17 changes: 17 additions & 0 deletions liuxin/liuxinclevel1/p03_Diophantus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <math.h>
#include <stdio.h>
const double INF=1e8,eps=1e-8;
int main(){
double i=0,j;
while (i<INF) {
if (fabs(i/6+i/12+i/7+9-i/2)<eps) {
printf("%.0f\n",i);
}
i+=0.1;
}
return 0;
}

/*
Ugly format
*/
16 changes: 16 additions & 0 deletions liuxin/liuxinclevel1/p04_narcissus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
int main(){
int i,j,k;
for (i=1;i<=9;++i)
for (j=0;j<=9;++j)
for (k=0;k<=9;++k)
if (i*i*i+j*j*j+k*k*k==i*100+j*10+k) {
printf("%d%d%d\n",i,j,k);
}

return 0;
}

/*
Ugly format
*/
31 changes: 31 additions & 0 deletions liuxin/liuxinclevel1/p05_allPrimes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <time.h>
#include <stdio.h>
#include <string.h>
const int MAXN=10000005;
bool b[MAXN];
int n,tot,prime[MAXN];
void get_prime(int n);
int main(){
scanf("%d",&n);
int tmp=clock();
get_prime(n);
for (int i=1;i<=tot;++i) {
printf("%d\n",prime[i]);
}
printf("time=%d ms\n",clock()-tmp);
return 0;
}
void get_prime(int n) {
memset(b,0,sizeof(b)); tot=0;
for (int i=2;i<=n;++i) {
if (!b[i]) prime[++tot]=i;
for (int j=1;j<=tot&&prime[j]*i<=n;++j) {
b[prime[j]*i]=1;
if (i%prime[j]==0) break;
}
}
}

/*
Ugly format
*/
32 changes: 32 additions & 0 deletions liuxin/liuxinclevel1/p06_Goldbach.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>
#include <string.h>
const int MAXN=10000005;
bool b[MAXN];
int n,tot,prime[MAXN];
void get_prime(int n);
int main(){
get_prime(100);
int i,j,k;
for (i=4;i<=100;i+=2) {
for (j=1;j<=tot;++j) {
for (k=1;k<=tot;++k) if (prime[j]+prime[k]==i) break;
if (prime[j]+prime[k]==i) break;
}
printf("%d=%d+%d\n",i,prime[j],prime[k]);
}
return 0;
}
void get_prime(int n) {
memset(b,0,sizeof(b)); tot=0;
for (int i=2;i<=n;++i) {
if (!b[i]) prime[++tot]=i;
for (int j=1;j<=tot&&prime[j]*i<=n;++j) {
b[prime[j]*i]=1;
if (i%prime[j]==0) break;
}
}
}

/*
Ugly format
*/
174 changes: 174 additions & 0 deletions liuxin/liuxinclevel1/p07_encrypt_decrypt.c

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions liuxin/liuxinclevel1/p08_hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
void work(int n,int x,int y,int z);
int main(){
int n;
scanf("%d",&n);
work(n,0,1,2);
return 0;
}
void work(int n,int x,int y,int z){
if (n==0) return;
work(n-1,x,z,y);
printf("%c --> %c\n",x+'a',z+'a');
work(n-1,y,x,z);
}
//Nice!
109 changes: 109 additions & 0 deletions liuxin/liuxinclevel1/p09_maze.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
typedef long long LL;
inline int read(){
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
return x*f;
}

const int MAXN=22;
int n,m,x,y,p,q,a[MAXN][MAXN];
int rand(int n);
int main(){
int i,j,k;
srand(time(0));
printf("Please input the length and the width:\n");
n=read(); m=read();
memset(a,0,sizeof(a));
for (i=1;i<=n*m/2;++i) { j=rand(n); k=rand(m); a[j][k]=1; }
system("cls");
for (i=n;i;--i) {
for (j=m;j;--j) if (!a[i][j]) break;
if (!a[i][j]) break;
}
a[i][j]=2; x=i; y=j;
for (i=1;i<=n;++i) {
for (j=1;j<=m;++j) if (!a[i][j]) break;
if (!a[i][j]) break;
}
a[i][j]=3; p=i; q=j;
for (i=1;i<=n;++i) {
for (j=1;j<=m;++j)
switch (a[i][j]) {
case 0:printf(" "); break;
case 1:printf("*"); break;
case 2:printf("U"); break;
case 3:printf("G"); break;
}
puts("");
}
printf("U:your position\n");
printf("G:your goal\n");
for (k=1;;++k) {
char ch=getch();
a[p][q]=0;
switch (ch) {
case 75:{
if (y>1&&!a[x][y-1]) {
a[x][y]=0;
a[x][--y]=2;
}
break;
}
case 77:{
if (y<m&&!a[x][y+1]) {
a[x][y]=0;
a[x][++y]=2;
}
break;
}
case 72:{
if (x>1&&!a[x-1][y]) {
a[x][y]=0;
a[--x][y]=2;
}
break;
}
case 80:{
if (x<n&&!a[x+1][y]) {
a[x][y]=0;
a[++x][y]=2;
}
break;
}
}
a[p][q]=3;
system("cls");
for (i=1;i<=n;++i) {
for (j=1;j<=m;++j)
switch (a[i][j]) {
case 0:printf(" "); break;
case 1:printf("*"); break;
case 2:printf("U"); break;
case 3:printf("G"); break;
}
puts("");
}
//printf("%d %d\n",k,n*m/2);
if (x==p&&y==q) {
printf("Congatulations!\n");
return 0;
}
if (k==n*m*2) {
printf("UUUUUUUUUUUUUUUUUUUUUUUUUUUSB!\n");
return 0;
}
}

return 0;
}
int rand(int n){ return (rand()<<16|rand())%n+1; }

/*
72 80 75 77
*/
Loading