Naxx

2873

div

ZhgDgE
NaiNo

SKG_G
KillLemon

fanbo
ETO

Mallknow
Qiang
lixiaoqian

Naxx
11天前

EX = 1p+2(1-p)p+3(1-p)^2p+....+(k-1)(1-p)^k-2p+k(1-p)^k

#include<iostream>
#include<stdio.h>
#include<math.h>

using namespace std;
double extract(double p,int i)
{
double P=ipow(1-p,i-1)p;
return P;
}
int main()
{
double p;//每抽概率
int k;//保底所需的次数
cin>>p>>k;
double mean=0;
for(int i=1;i<k;i++)
{
mean=mean+extract(p,i);
}
double last=k*pow(1-p,k-1);
mean=mean+last;
printf(“%lf”,mean);//数学期望值
printf(“%lf”,1/mean);//实际每抽的概率
return 0;
}


Naxx
22天前

#### java 代码

import java.util.*;
class Main{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int l1,r1;
while((m--)!=0){
int n=sc.nextInt();
int t=1;
for(int i=0;i<n;i++)
{
l1=sc.nextInt();
r1=sc.nextInt();
if(t<l1)
{
t=l1;
}
if(t>r1) System.out.print(0+" ");
else {System.out.print(t+" ");
t++;}

}
System.out.println();
}

}
}


Naxx
22天前

#### C 代码

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int count = 0;
//判断当前棋子所在位置是否安全的函数
int notdange(int row,int rank, int(*chess)[8])
{
int flag = 1,i,j;
//判断列
for (i = 0; i < 8; i++)
{
if (*(*(chess + i) + rank )!= 0)
{
flag = 0;
break;
}
}
//判断左上
for (i = row, j = rank; i >= 0&&j>=0; i--,j--)
{
if (*(*(chess + i) + j) != 0)
{
flag = 0;
break;
}
}
//判断右下
for (i = row, j = rank; i < 8 && j <8; i++, j++)
{
if (*(*(chess + i) + j) != 0)
{
flag = 0;
break;
}
}
//判断右上
for (i = row, j = rank; i >= 0 && j < 8; i--, j++)
{
if (*(*(chess + i) + j) != 0)
{
flag = 0;
break;
}
}
//判断左下
for (i = row, j = rank; i <8  && j >= 0; i++, j--)
{
if (*(*(chess + i) +j) != 0)
{
flag = 0;
break;
}
}
return flag;
}
//主要的八皇后递归算法
void EithtQueen(int row,int rank,int (*chess)[8])
{
int chess2[8][8];//临时棋盘，用作打印

for (int i = 0; i < 8; i++)//初始化
{
for (int j = 0; j < 8; j++)
{
chess2[i][j] =chess[i][j];
}
}
//第八行元素确定后打印输出
if (8 == row)
{
printf("第 %d 种\n", count + 1);
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
printf("%d ",*(*(chess2+i)+j)) ;
}
printf("\n");
}
printf("\n");
count++;
}
else
{
//主要实现棋盘从1-1到8-8每个位置开始的函数
for (int j = 0; j < rank; j++)
{
if ( notdange(row,j,chess) )
{
for (int i = 0; i < 8; i++)
{
*(*(chess2 + row) + i)=0;
}
*(*(chess2 + row) + j) = 1;

EithtQueen(row + 1, rank, chess2);//每一列检查算作一次循环结束，知道j列第8行才会被输出一次
}
}
}
}
int main()
{
int chess[8][8];
memset(chess,0,sizeof(chess));
EithtQueen(0, 8, chess);
printf("共有 %d 种方法", count);
return 0;
}



Naxx
2个月前
import java.util.*;
class Main{
public static Long qmi(Long a, Long b, Long p) {
Long res = 1 % p;
while (b > 0) {
if ((b & 1) == 1) res = (res * a) % p;
a = (a * a) % p;
b >>= 1;
}
return res;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
Long a=sc.nextLong();
Long b=sc.nextLong();
Long c=sc.nextLong();
System.out.println(qmi(a,b,c));

}

}


Naxx
6个月前

import java.util.*;
class Main{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int a[]=new int[n];
int b[]=new int[m];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();

}
for(int i=0;i<m;i++)
{
b[i]=sc.nextInt();

}
int i=0,j=0;
while(i<n&&j<m)
{
if(a[i]==b[j])
{
i++;
}
j++;
}
if(i==n) System.out.println("Yes");
else System.out.println("No");
}
}


Naxx
7个月前

import java.io.*;
import java.util.Queue;

class node{
int t, x, y;
public node(int tt, int xx, int yy){
t = tt;
x = xx;
y = yy;
}
}
public class Main{
//上右下左
static int dx []= {-1, 0, 1, 0};
static int dy []= {0, 1, 0, -1};
public static int bfs(char [][] f, int x, int y, int n, int m){
boolean vis[][] = new boolean[n][m];
vis[x][y] = true;
while(! q.isEmpty()) {
if( f[sx][sy] == 'E') return st;
for(int i = 0; i < 4; i++) {
int nx = sx + dx[i], ny = sy + dy[i];
if(nx < 0|| nx >= n || ny < 0 || ny >= m || f[nx][ny] == '#' || vis[nx][ny])
continue;
vis[nx][ny] = true;
q.add(new node( st + 1, nx, ny));
}

}
return 0;

}
public static void main(String args[]) throws Exception{
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
while(T-- > 0){
int n = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
char [][] f= new char[n][m];
for(int i = 0; i < n; i++) f[i] = bf.readLine().toCharArray();
int sx = 0, sy = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(f[i][j] == 'S'){
sx = i;
sy = j;
}
int ans  = bfs(f, sx, sy, n, m) ;
if( ans == 0)
log.write("oop!\n");
else
log.write(ans+"\n");
}
log.flush();
log.close();
bf.close();
}
}


Naxx
7个月前

import java.util.*;
class Main{
static boolean st[]=new boolean[40];
public static void main(String[] args)
{
int T,n,m;
Scanner sc=new Scanner(System.in);
T=sc.nextInt();
int w[][]=new int[40][40];
for(int s=1;s<=T;s++)
{
n=sc.nextInt();
m=n*n;
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
w[i][j]=sc.nextInt();
}
}
if(check_row(w,m)&&check_col(w,m)&&check_cell(w,m,n))
System.out.println("Case #"+s+": Yes");
else System.out.println("Case #"+s+": No");
}
}
static boolean check_row(int w[][],int m)
{
for(int i=0;i<m;i++)
{
Arrays.fill(st,false);
for(int j=0;j<m;j++)
{
int t=w[i][j];
if(t<1||t>m) return false;
if(st[t]==true) return false;
st[t]=true;
}
}
return true;
}
static boolean check_col(int w[][],int m)
{
for(int i=0;i<m;i++)
{
Arrays.fill(st,false);
for(int j=0;j<m;j++)
{
int t=w[j][i];
if(t<1||t>m) return false;
if(st[t]==true) return false;
st[t]=true;
}
}
return true;
}
static boolean check_cell(int w[][],int m,int n)
{
for(int x=0;x<m;x+=n)
for(int y=0;y<m;y+=n)
{
Arrays.fill(st,false);
for(int dx=0;dx<n;dx++)
for(int dy=0;dy<n;dy++)
{
int t=w[x+dx][y+dy];
if(t<1||t>m) return false;
if(st[t]==true) return false;
st[t]=true;
}
}
return true;
}
}


Naxx
7个月前

import java.util.*;
class Main{
public static void main(String[] args)
{
int N=30,M=30010;
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();int n=sc.nextInt();
int f[]=new int[M];

for (int i = 1; i <= n; i ++ )
{
int v, w;
v=sc.nextInt();
w=sc.nextInt();
w = v * w;
for (int j = m; j >= v; j -- )
f[j] = Math.max(f[j], f[j - v] + w);
}
System.out.println(f[m]);
}
}


Naxx
7个月前

import java.util.*;
class Main{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int T,n,m;
T=sc.nextInt();
int w[][]=new int[110][110];
int f[][]=new int[110][110];
while(T-->0)
{
n=sc.nextInt();
m=sc.nextInt();
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
w[i][j]=sc.nextInt();

for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
f[i][j] = Math.max(f[i - 1][j], f[i][j - 1]) + w[i][j];
System.out.println(f[n][m]);
}
}
}


Naxx
7个月前

import java.io.*;
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int count = sc.nextInt();
int[] arr = new int[size];
for(int i = 0; i < size; i++) {
arr[i] = sc.nextInt();
}
while(count-- > 0) {
arr = next(arr);
}
for(int i = 0; i < size; i++) {
System.out.print(arr[i] + " ");
}
}
public static int[] next(int[] arr){
int len = arr.length;
int st = 0;
int ed = 0;
for(int i = len - 2; i >= 0; i--) {
if(arr[i] < arr[i + 1]) {
st = i;
break;
}
}
for(int i = st; i < len; i++) {
if(arr[i] > arr[st]) {
ed = i;
}
}
arr = swap(arr, st, ed);
arr = reverse(arr, st + 1, len - 1);
return arr;
}

public static int[] swap(int[] arr, int m, int n) {
int temp = arr[m];
arr[m] = arr[n];
arr[n] = temp;
return arr;
}

public static int[] reverse(int[] arr, int left, int right) {
while(left < right) {
arr = swap(arr, left, right);
left++;
right--;
}
return arr;
}
}