Acwer

https://acwer.github.io/

2.3万

Stair
000_2
18018859110
StarLi9ht
charley123
rfx
hongk_bb
DraymoNd_
24点必睡
Jiarui.X
yxc的小迷妹1

violet_garden
yxc的小迷妹

3203963267@qq.com

Acwer
12小时前
class Solution {
List<String> res = new ArrayList<>();
public List<String> letterCasePermutation(String s) {
char a[] = s.toCharArray();
dfs(a,0);
return res;
}

public void dfs(char s[],int u){
if(u==s.length){
return;
}else{
if(s[u]>='0'&&s[u]<='9') dfs(s,u+1);
else{
//首先不改变字母，让它dfs下去
dfs(s,u+1);
//修改元素，然后继续遍历下去
s[u]=changeLetter(s[u]);
dfs(s,u+1);
//恢复现场
s[u]=changeLetter(s[u]);
}
}
}

public char changeLetter(char c){
if(c>='a'&&c<='z') return (char)(c-32);
else return (char)(c+32);
}
}

Acwer
16小时前

Acwer
16小时前
import java.util.Scanner;

public class Main {
static int mod = 100003;

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long m = scanner.nextLong();
long n = scanner.nextLong();
System.out.println((quick_sort(m, n, mod)-m*quick_sort(m-1, n-1, mod)%mod+mod)%mod);

scanner.close();
}

public static long quick_sort(long a, long b, long mod) {
long ans = 1;
while (b != 0) {
if (b % 2 == 1)
ans = ans * a % mod;
a = (a * a) % mod;
b = b / 2;
}
return ans;
}
}

Acwer
16小时前
import java.util.Scanner;

public class Main {
static int mod=200907;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while(T-->0){
long a = scanner.nextLong();
long b = scanner.nextLong();
long c = scanner.nextLong();
long k = scanner.nextLong();
if(a+c==2*b) System.out.println((a+(b-a)*(k-1))%mod);
else System.out.println(a*quick_power(b/a,k-1,mod)%mod);
}
scanner.close();
}
public static long quick_power(long a,long b,long p){
long ans=1;
while(b!=0){
//如果b是奇数。
if(b%2==1) ans=ans*a%p;
a=(a*a)%p;
b=b/2;
}
return ans%p;
}
}

Acwer
16小时前
import java.util.Scanner;

public class Main {
static int mod=200907;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while(T-->0){
long a = scanner.nextLong();
long b = scanner.nextLong();
long c = scanner.nextLong();
long k = scanner.nextLong();
if(a+c==2*b) System.out.println((a+(b-a)*(k-1))%mod);
else System.out.println(a*quick_power(b/a,k-1,mod)%mod);
}
scanner.close();
}

public static long quick_power(long a,long b,long p){
long ans=1;
while(b!=0){
//如果b是奇数。
if(b%2==1){
ans=ans*a%p;

}
a=(a*a)%p;
b=b/2;
}
return ans%p;
}
}

Acwer
17小时前
import java.util.Scanner;

public class Main {
static boolean st[] = new boolean[1000010];
static int prime[] = new int[1000010];
static int cnt;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
get_prime(N);
for(int i=0;i<cnt;i++){
int s=0;
int p=prime[i];
for(int j=N;j!=0;j=j/p){
s=s+j/p;   //N个中包含p的质因子的数，即为s。
}
System.out.println(p+" "+s);
}
scanner.close();
}

public static void get_prime(int n){
for(int i=2;i<=n;i++){
if(st[i]==false) prime[cnt++]=i;
for(int j=0;j<cnt;j++)
if(prime[j]*i<=n) st[prime[j]*i]=true;
else break;
}
}

}

Acwer
1天前
import java.util.Scanner;

public class Main {
static int prime[] = new int[1000010];
static boolean st[] = new boolean[1000010];
static int cnt;
static int v[] = new int[1000010];
static int n;
public static void main(String[] args) {
get_prime(1000000);
Scanner scanner = new Scanner(System.in);
while(true){
n = scanner.nextInt();

if(n==0) break;
for(int i=0;i<cnt;i++){
if(st[n-prime[i]]==false){
System.out.println(n+" = "+prime[i]+" + "+(n-prime[i]));
break;
}
}

}

scanner.close();
}
public static void get_prime(int n){
//最早取的i一定是质数。
for(int i=2;i<=n;i++){
if(st[i]!=true){   //表示未被筛掉
prime[cnt++]=i;
}
for(int j=0;j<cnt;j++){
if(prime[j]*i<=n){
st[prime[j]*i]=true;
}
else{
break;
}
/*
我觉得这条语句是多余的。
if(i%prime[j]==0) break;
*/
}
}
}
}

Acwer
1天前
import java.util.Scanner;

public class Main {
static boolean st[][] = new boolean[10][10];
static int ans = 0;
static int n, m;
static int dx[] = { -2, -1, 1, 2, 2, 1, -1, -2 };
static int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
while (N-- > 0) {
n = scanner.nextInt();
m = scanner.nextInt();
int x = scanner.nextInt();
int y = scanner.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
st[i][j] = false;
}
}

ans = 0;
dfs(x, y, 1);
System.out.println(ans);
}
scanner.close();
}

public static void dfs(int x, int y, int cnt) {
if (cnt == n * m) {
ans++;
return;
}
st[x][y] = true;
// 状态转移
for (int i = 0; i < 8; i++) {
int a = x + dx[i];
int b = y + dy[i];
if (a < 0 || a >= n || b < 0 || b >= m)
continue;
if (st[a][b] == true)
continue;
dfs(a, b, cnt + 1);
}
st[x][y] = false;
}
}

Acwer
1天前
import java.util.Scanner;

public class Main {
static char g[][] = new char[61][61];
static int start_x,start_y;
static boolean st[][] = new boolean[61][61];
static int dx[]={-1,1,0,0};
static int dy[]={0,0,-1,1};
static int w,h;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(true){
w = scanner.nextInt();
h = scanner.nextInt();
int cnt=0;
if(w==0&&h==0) break;
for(int i=0;i<h;i++){
String temp= scanner.next();
for(int j=0;j<w;j++){
g[i][j] = temp.charAt(j);
if(g[i][j]=='@'){
start_x=i;
start_y=j;
}
}
}

for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
st[i][j]=false;
}
}
System.out.println(dfs(start_x,start_y));
}
scanner.close();
}
public static int dfs(int start_x,int start_y){
int cnt=1;
st[start_x][start_y]=true;
for(int i=0;i<4;i++){
int x=start_x+dx[i];
int y=start_y+dy[i];
if(x<0||x>=h||y<0||y>=w) continue;
if(g[x][y]!='.') continue;
if(st[x][y]==true) continue;
cnt=cnt+dfs(x,y);
}
return cnt;
}
}

Acwer
1天前
class Solution {
public int findLengthOfLCIS(int[] nums) {
int res=1;
int ans=1;
for(int i=1;i<nums.length;i++)
if(nums[i]>nums[i-1]){
res++;
ans=Math.max(res,ans);
}
else res=1;
return ans;
}
}