- 點擊跳轉(zhuǎn)專欄=>Unity3D特效百例
- 點擊跳轉(zhuǎn)專欄=>案例項目實戰(zhàn)源碼
- 點擊跳轉(zhuǎn)專欄=>游戲腳本-輔助自動化
- 點擊跳轉(zhuǎn)專欄=>Android控件全解手冊
- 點擊跳轉(zhuǎn)專欄=>Scratch編程案例
- 點擊跳轉(zhuǎn)=>軟考全系列
- 點擊跳轉(zhuǎn)=>藍(lán)橋系列
??關(guān)于作者
專注于Android/Unity和各種游戲開發(fā)技巧,以及各種資源分享(網(wǎng)站、工具、素材、源碼、游戲等)
有什么需要歡迎底部卡片私我,獲取更多支持,交流讓學(xué)習(xí)不再孤單。
??實踐過程
需要所有整理的文檔可底部卡片聯(lián)系我,直接發(fā)壓縮包。
??地宮取寶
問題描述
X 國王有一個地宮寶庫。是 n x m 個格子的矩陣。每個格子放一件寶貝。每個寶貝貼著價值標(biāo)簽。
地宮的入口在左上角,出口在右下角。
小明被帶到地宮的入口,國王要求他只能向右或向下行走。
走過某個格子時,如果那個格子中的寶貝價值比小明手中任意寶貝價值都大,小明就可以拿起它(當(dāng)然,也可以不拿)。
當(dāng)小明走到出口時,如果他手中的寶貝恰好是k件,則這些寶貝就可以送給小明。
請你幫小明算一算,在給定的局面下,他有多少種不同的行動方案能獲得這k件寶貝。
輸入格式
輸入一行3個整數(shù),用空格分開:n m k (1<=n,m<=50, 1<=k<=12)
接下來有 n 行數(shù)據(jù),每行有 m 個整數(shù) Ci (0<=Ci<=12)代表這個格子上的寶物的價值
輸出格式
要求輸出一個整數(shù),表示正好取k個寶貝的行動方案數(shù)。該數(shù)字可能很大,輸出它對 1000000007 取模的結(jié)果。
樣例輸入
2 2 2
1 2
2 1
樣例輸出
2
樣例輸入
2 3 2
1 2 3
2 1 5
樣例輸出
14
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
public class Main
{
private static StreamTokenizer tokenizer = new StreamTokenizer(
new InputStreamReader(System.in));
private static PrintWriter outWriter = new PrintWriter(
new OutputStreamWriter(System.out));
private static int n, m, k;
private static int[][] table;
private static final int MOD = 1000000007;
private static long[][][][] state;
private static long dfs(int i, int j, int num, int max)
{
if (state[i][j][num][max] != -1)
return state[i][j][num][max];
long currentAns = 0;
if (i == n - 1 && j == m - 1)
{
if (num == k || max < table[i][j] && num + 1 == k)
currentAns++;
state[i][j][num][max] = currentAns;
return currentAns;
}
if (i + 1 < n)
{
currentAns += dfs(i + 1, j, num, max);
if (max < table[i][j] && num + 1 <= k)
currentAns += dfs(i + 1, j, num + 1, table[i][j]);
}
if (j + 1 < m)
{
currentAns += dfs(i, j + 1, num, max);
if (max < table[i][j] && num + 1 <= k)
currentAns += dfs(i, j + 1, num + 1, table[i][j]);
}
state[i][j][num][max] = currentAns;
return currentAns;
}
public static void main(String[] args) throws Exception
{
tokenizer.nextToken();
n = (int) tokenizer.nval;
tokenizer.nextToken();
m = (int) tokenizer.nval;
tokenizer.nextToken();
k = (int) tokenizer.nval;
table = new int[n][m];
state = new long[n][m][k + 1][14];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int t = 0; t <= k; t++)
Arrays.fill(state[i][j][t], -1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
tokenizer.nextToken();
table[i][j] = (int) tokenizer.nval;
table[i][j]++;
}
long ret = dfs(0, 0, 0, 0);
outWriter.println(ret % MOD);
outWriter.flush();
}
}
??斐波那契
問題描述
斐波那契數(shù)列大家都非常熟悉。它的定義是:
f(x) = 1 … (x=1,2)
f(x) = f(x-1) + f(x-2) … (x>2)
對于給定的整數(shù) n 和 m,我們希望求出:
f(1) + f(2) + … + f(n) 的值。但這個值可能非常大,所以我們把它對 f(m) 取模。
公式如下圖
但這個數(shù)字依然很大,所以需要再對 p 求模。
輸入格式
輸入為一行用空格分開的整數(shù) n m p (0 < n, m, p < 10^18)
輸出格式
輸出為1個整數(shù),表示答案
樣例輸入
2 3 5
樣例輸出
0
樣例輸入
15 11 29
樣例輸出
25
import java.math.BigInteger;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
long n,m;
n=sc.nextLong();
m=sc.nextLong();
BigInteger p=sc.nextBigInteger(),fn,fm;
if(n+2>m)
{
fm=think(m,null);
fn=think(n+2,fm).subtract(new BigInteger("1"));
System.out.println(fn.remainder(fm).remainder(p));
}
else
{
fn=think(n+2,p).subtract(new BigInteger("1"));
System.out.println(fn.remainder(p));
}
}
private static BigInteger think(long m,BigInteger mod) {
// TODO Auto-generated method stub
BigInteger a1=new BigInteger("1"),a2=new BigInteger("1"),x[][];
if(m==1)return a1;
else if(m==2)return a2;
else
{
x=new BigInteger[2][2];
x[0][0]=new BigInteger("1");
x[0][1]=new BigInteger("1");
x[1][0]=new BigInteger("1");
x[1][1]=new BigInteger("0");
x=doublex(x,m-2,mod);
return x[0][0].add(x[0][1]);
}
}
private static BigInteger[][] doublex(BigInteger[][] x, long n,BigInteger mod) {
// TODO Auto-generated method stub
BigInteger x2[][];
x2=new BigInteger[2][2];
if(n==1)return x;
else
{
if(n%2==1)return cheng(doublex(cheng(x,x,mod),n/2,mod),x,mod);
else return doublex(cheng(x,x,mod),n/2,mod);
}
}
private static BigInteger[][] cheng(BigInteger[][] x, BigInteger[][] y,BigInteger mod) {
// TODO Auto-generated method stub
BigInteger z[][];
z=new BigInteger[2][2];
if(mod!=null)
{
z[0][0]=x[0][0].multiply(y[0][0]).add(x[1][0].multiply(y[0][1])).remainder(mod);
z[0][1]=x[0][0].multiply(y[0][1]).add(x[0][1].multiply(y[1][1])).remainder(mod);
z[1][0]=x[1][0].multiply(y[0][0]).add(x[1][1].multiply(y[1][0])).remainder(mod);
z[1][1]=x[1][0].multiply(y[0][1]).add(x[1][1].multiply(y[1][1])).remainder(mod);
return z;
}
z[0][0]=x[0][0].multiply(y[0][0]).add(x[1][0].multiply(y[0][1]));
z[0][1]=x[0][0].multiply(y[0][1]).add(x[0][1].multiply(y[1][1]));
z[1][0]=x[1][0].multiply(y[0][0]).add(x[1][1].multiply(y[1][0]));
z[1][1]=x[1][0].multiply(y[0][1]).add(x[1][1].multiply(y[1][1]));
return z;
}
}
??波動數(shù)列
問題描述
觀察這個數(shù)列:
1 3 0 2 -1 1 -2 …
這個數(shù)列中后一項總是比前一項增加2或者減少3。
棟棟對這種數(shù)列很好奇,他想知道長度為 n 和為 s 而且后一項總是比前一項增加a或者減少b的整數(shù)數(shù)列可能有多少種呢?
輸入格式
輸入的第一行包含四個整數(shù) n s a b,含義如前面說述。
輸出格式
輸出一行,包含一個整數(shù),表示滿足條件的方案數(shù)。由于這個數(shù)很大,請輸出方案數(shù)除以100000007的余數(shù)。
樣例輸入
4 10 2 3
樣例輸出
2
樣例說明
這兩個數(shù)列分別是2 4 1 3和7 4 1 -2。
數(shù)據(jù)規(guī)模和約定
對于10%的數(shù)據(jù),1<=n<=5,0<=s<=5,1<=a,b<=5;
對于30%的數(shù)據(jù),1<=n<=30,0<=s<=30,1<=a,b<=30;
對于50%的數(shù)據(jù),1<=n<=50,0<=s<=50,1<=a,b<=50;
對于70%的數(shù)據(jù),1<=n<=100,0<=s<=500,1<=a, b<=50;
對于100%的數(shù)據(jù),1<=n<=1000,-1,000,000,000<=s<=1,000,000,000,1<=a, b<=1,000,000。
public class Main {
public static void main(String[] args) {
int mod = 100000007;
int n, s, a, b, i, j, t;
int x[][] = new int[1001][1001];
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
s = sc.nextInt();
a = sc.nextInt();
b = sc.nextInt();
b %= n;
b *= -1;
while (b < 0)
b += n;
a %= n;
s %= n;
while (s < 0)
s += n;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
x[i][j] = 0;
x[1][a] = x[1][b] = 1;
for (i = 1; i < n - 1; i++)
for (j = 0; j < n; j++) {
t = (j + a * (i + 1)) % n;
x[i + 1][t] += x[i][j];
x[i + 1][t] %= mod;
t = (j + b * (i + 1)) % n;
t %= n;
x[i + 1][t] += x[i][j];
x[i + 1][t] %= mod;
}
System.out.printf("%d\n", x[n - 1][s]);
}
}
??小朋友排隊
問題描述
n 個小朋友站成一排?,F(xiàn)在要把他們按身高從低到高的順序排列,但是每次只能交換位置相鄰的兩個小朋友。
每個小朋友都有一個不高興的程度。開始的時候,所有小朋友的不高興程度都是0。
如果某個小朋友第一次被要求交換,則他的不高興程度增加1,如果第二次要求他交換,則他的不高興程度增加2(即不高興程度為3),依次類推。當(dāng)要求某個小朋友第k次交換時,他的不高興程度增加k。
請問,要讓所有小朋友按從低到高排隊,他們的不高興程度之和最小是多少。
如果有兩個小朋友身高一樣,則他們誰站在誰前面是沒有關(guān)系的。
輸入格式
輸入的第一行包含一個整數(shù)n,表示小朋友的個數(shù)。
第二行包含 n 個整數(shù) H1 H2 … Hn,分別表示每個小朋友的身高。
輸出格式
輸出一行,包含一個整數(shù),表示小朋友的不高興程度和的最小值。
樣例輸入
3
3 2 1
樣例輸出
9
樣例說明
首先交換身高為3和2的小朋友,再交換身高為3和1的小朋友,再交換身高為2和1的小朋友,每個小朋友的不高興程度都是3,總和為9。
數(shù)據(jù)規(guī)模和約定
對于10%的數(shù)據(jù), 1<=n<=10;
對于30%的數(shù)據(jù), 1<=n<=1000;
對于50%的數(shù)據(jù), 1<=n<=10000;
對于100%的數(shù)據(jù),1<=n<=100000,0<=Hi<=1000000。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
static int N = 100010;
static int MAX = 1000100;
static int[] C = new int[MAX];
static int[] S = new int[MAX];
static int[] b = new int[N];
static long[] total = new long[N];
static long ans;
static int[] num = new int[N];
static int T, s, t, i, j;
static int Lowbit(int x) {
return x & (-x);
}
static void add(int pos, int num, int[] P) {
while (pos <= MAX) {
P[pos] += num;
pos += Lowbit(pos);
}
}
static int Sum(int end, int[] P) {
int cnt = 0;
while (end > 0) {
cnt += P[end];
end -= Lowbit(end);
}
return cnt;
}
static void init() {
total[0] = 0;
for (int i = 1; i < N; ++i) {
total[i] = total[i - 1] + i;
}
}
public static void main(String[] args) throws IOException {
init();
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
T = Integer.parseInt(buf.readLine());
String[] str = buf.readLine().split(" ");
for (int j = 0; j < T; j++) {
num[j] = Integer.parseInt(str[j]);
add(num[j] + 1, 1, C);
b[j] = j - Sum(num[j], C);
b[j] -= Sum(num[j] + 1, C) - Sum(num[j], C) - 1;
}
ans = 0;
for (int j = T - 1; j > -1; --j) {
add(num[j] + 1, 1, S);
b[j] += Sum(num[j], S);
ans += total[b[j]];
}
System.out.println(ans);
}
}
??其他
??作者:小空和小芝中的小空
??轉(zhuǎn)載說明-務(wù)必注明來源:https://zhima.blog.csdn.net/
??這位道友請留步??,我觀你氣度不凡,談吐間隱隱有王者霸氣??,日后定有一番大作為???。?!旁邊有點贊??收藏??今日傳你,點了吧,未來你成功??,我分文不取,若不成功??,也好回來找我。文章來源:http://www.zghlxwxcb.cn/news/detail-514857.html
溫馨提示:點擊下方卡片獲取更多意想不到的資源。文章來源地址http://www.zghlxwxcb.cn/news/detail-514857.html
到了這里,關(guān)于藍(lán)橋杯專題-試題版-【地宮取寶】【斐波那契】【波動數(shù)列】【小朋友排隊】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!