1. 程式人生 > 其它 >excel 賦值_Python 3 學習筆記:Excel 基礎操作(二)

excel 賦值_Python 3 學習筆記:Excel 基礎操作(二)

問題 A: 火星人問題

時間限制:1Sec記憶體限制:64 MB
提交狀態

題目描述

人類終於登上了火星的土地並且見到了神祕的火星人。人類和火星人都無法理解對方的語言,但是我們的科學家發明了一種用數字交流的方法。這種交流方法是這樣的,首先,火星人把一個非常大的數字告訴人類科學家,科學家破解這個數字的含義後,再把一個很小的數字加到這個大數上面,把結果告訴火星人,作為人類的回答。

火星人用一種非常簡單的方式來表示數字――掰手指。火星人只有一隻手,但這隻手上有成千上萬的手指,這些手指排成一列,分別編號為1,2,3……。火星人的任意兩根手指都能隨意交換位置,他們就是通過這方法計數的。

一個火星人用一個人類的手演示瞭如何用手指計數。如果把五根手指――拇指、食指、中指、無名指和小指分別編號為1,2,3,4和5,當它們按正常順序排列時,形成了5位數12345,當你交換無名指和小指的位置時,會形成5位數12354,當你把五個手指的順序完全顛倒時,會形成54321,在所有能夠形成的120個5位數中,12345最小,它表示1;12354第二小,它表示2;54321最大,它表示120。下表展示了只有3根手指時能夠形成的6個3位數和它們代表的數字:

三進位制數
123 132 213 231 312 321

代表的數字
1 2 3 4 5 6

現在你有幸成為了第一個和火星人交流的地球人。一個火星人會讓你看他的手指,科學家會告訴你要加上去的很小的數。你的任務是,把火星人用手指表示的數與科學家告訴你的數相加,並根據相加的結果改變火星人手指的排列順序。輸入資料保證這個結果不會超出火星人手指能表示的範圍。

輸入

包括三行,第一行有一個正整數N,表示火星人手指的數目(1 <= N <= 10000)。第二行是一個正整數M,表示要加上去的小整數(1 <= M <= 100)。下一行是1到N這N個整數的一個排列,用空格隔開,表示火星人手指的排列順序。

輸出

只有一行,這一行含有N個整數,表示改變後的火星人手指的排列順序。每兩個相鄰的數中間用一個空格分開,不能有多餘的空格。

樣例輸入Copy

5
3
1 2 3 4 5

樣例輸出Copy

1 2 4 5 3

提示

對於全部的資料,N<=10000;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>

#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
int n, m, a[10001]; cin >> n >> m;

for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) next_permutation(a,a+n);
for(int i = 0; i < n; i++) cout << a[i] << " ";

return 0;
}

問題 B: FBI樹

時間限制:1Sec記憶體限制:64 MB
提交狀態

題目描述

上古文明遺蹟的探險任務最終決定交由墨老師帶領完成。他們開啟第一個寶藏的條件是解決FBI樹問題。所謂FBI樹的描述如下:

我們可以把由“0”和“1”組成的字串分為三類:全“0”串稱為B串,全“1”串稱為I串,既含“0”又含“1”的串則稱為F串。FBI樹是一種二叉樹,它的結點型別也包括F結點,B結點和I結點三種。由一個長度為2N的“01”串S可以構造出一棵FBI樹T,遞迴的構造方法如下:

(1) T的根結點為R,其型別與串S的型別相同。

(2) 若串S的長度大於1,將串S從中間分開,分為等長的左右子串S1和S2;由左子串S1構造R的左子樹T1,由右子串S2構造R的右子樹T2。

現在給定一個長度為2N的“01”串,請用上述構造方法構造出一棵FBI樹,並輸出它的後序遍歷序列。

輸入

第一行是一個整數N(0≤N≤10),第二行是一個長度為2N的“01”串。

輸出

包括一行,這一行只包含一個字串,即FBI樹的後序遍歷序列。

樣例輸入Copy

3
10001011

樣例輸出Copy

IBFBBBFIBFIIIFF

提示


對於40%的資料,N≤2;
對於全部的資料,N≤10。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

char s[1050];

void Fact(int x, int st, int ed)
{
if(x < 0) return ;

int mid = (st + ed) / 2;
if(x == 0)
{
if(s[st] == '0') cout<<'B';
if(s[st] == '1') cout<<'I';
}
else if(x > 0)
{
Fact(x - 1, st, mid);
Fact(x - 1, mid + 1, ed);
bool f0 = false;
bool f1 = false;
for(int i = st; i <= ed; i++)
{
if(s[i] == '0') f0 = true;
if(s[i] == '1') f1 = true;
if(f0 && f1) break;
}
if(f0 && f1) cout<<'F';
else if(f0) cout<<'B';
else if(f1) cout<<'I';
}
return ;
}

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
int n; cin>>n;
int cnt = pow(2, n);// cout<<cnt<<'\n';
for(int i = 1; i <= cnt; i++)
{
cin>>s[i];
// cout<<s[i];
}
// cout<<'\n';
Fact(n, 1, cnt);
cout<<'\n';
return 0;
}

問題 C: 不高興的津津

時間限制:1Sec記憶體限制:128 MB
提交狀態

題目描述

津津上初中了。媽媽認為津津應該更加用功學習,所以津津除了上學之外,還要參加媽媽為她報名的各科複習班。另外每週媽媽還會送她去學習朗誦、舞蹈和鋼琴。但是津津如果一天上課超過八個小時就會不高興,而且上得越久就會越不高興。假設津津不會因為其它事不高興,並且她的不高興不會持續到第二天。請你幫忙檢查一下津津下週的日程安排,看看下週她會不會不高興;如果會的話,哪天最不高興。

輸入

輸入包括七行資料,分別表示週一到週日的日程安排。每行包括兩個小於10的非負整數,用空格隔開,分別表示津津在學校上課的時間和媽媽安排她上課的時間。

輸出

輸出包括一行,這一行只包含一個數字。如果不會不高興則輸出0,如果會則輸出最不高興的是周幾(用1, 2, 3, 4, 5, 6, 7分別表示週一,週二,週三,週四,週五,週六,週日)。如果有兩天或兩天以上不高興的程度相當,則輸出時間最靠前的一天。

樣例輸入Copy

5 3
6 2
7 2
5 3
5 4
0 4
0 6

樣例輸出Copy

3

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
int max = 0; int vis = 0;
int a,b;
for(int i = 1; i <= 7; i++)
{
cin>>a>>b;
if(a + b > 8 && a + b > max)
{
max = (a + b);
vis = i;
}
}
cout<<vis<<'\n';
return 0;
}

問題 D: 花生採摘

時間限制:1Sec記憶體限制:128 MB
提交狀態

題目描述

魯賓遜先生有一隻寵物猴,名叫多多。這天,他們兩個正沿著鄉間小路散步,突然發現路邊的告示牌上貼著一張小小的紙條:“歡迎免費品嚐我種的花生!——熊字”。
魯賓遜先生和多多都很開心,因為花生正是他們的最愛。在告示牌背後,路邊真的有一塊花生田,花生植株整齊地排列成矩形網格(如圖1)。有經驗的多多一眼就能看出,每棵花生植株下的花生有多少。為了訓練多多的算術,魯賓遜先生說:“你先找出花生最多的植株,去採摘它的花生;然後再找出剩下的植株裡花生最多的,去採摘它的花生;依此類推,不過你一定要在我限定的時間內回到路邊。”
我們假定多多在每個單位時間內,可以做下列四件事情中的一件:
1) 從路邊跳到最靠近路邊(即第一行)的某棵花生植株;
2) 從一棵植株跳到前後左右與之相鄰的另一棵植株;
3) 採摘一棵植株下的花生;
4) 從最靠近路邊(即第一行)的某棵花生植株跳回路邊。
現在給定一塊花生田的大小和花生的分佈,請問在限定時間內,多多最多可以採到多少個花生?注意可能只有部分植株下面長有花生,假設這些植株下的花生個數各不相同。
例如在圖2所示的花生田裡,只有位於(2, 5), (3, 7), (4, 2), (5, 4)的植株下長有花生,個數分別為13, 7, 15, 9。沿著圖示的路線,多多在21個單位時間內,最多可以採到37個花生。

輸入

輸入的第一行包括三個整數,M, N和K,用空格隔開;表示花生田的大小為M * N(1 <= M, N <= 20),多多采花生的限定時間為K(0 <= K <= 1000)個單位時間。接下來的M行,每行包括N個非負整數,也用空格隔開;第i + 1行的第j個整數Pij(0 <= Pij <= 500)表示花生田裡植株(i, j)下花生的數目,0表示該植株下沒有花生。

輸出

輸出包括一行,這一行只包含一個整數,即在限定時間內,多多最多可以採到花生的個數。

樣例輸入Copy

6 7 21
0 0 0 0 0 0 0
0 0 0 0 13 0 0
0 0 0 0 0 0 7
0 15 0 0 0 0 0
0 0 0 9 0 0 0
0 0 0 0 0 0 0

樣例輸出Copy

37

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

typedef struct
{
int h,l,w,t,bk;
}Node;

Node a[405] = {0};

bool cmp(Node x, Node y)
{
return x.w > y.w;
}

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
int H,L,T; cin>>H>>L>>T;

int vis = 1;
for(int i = 1; i <= H; i++)
{
for(int j = 1; j <= L; j++)
{
a[vis].h = i; a[vis].l = j;
cin>>a[vis].w;
vis++;
// cout<<a[vis].w;
}
}
sort(a + 1, a + 1 + H * L, cmp);
// for(int i = 1; i <= H * L; i++) cout<<a[i].w;
for(int i = 1; i <= H * L; i++)
{
if(a[i].w)
{
if(i == 1)
{
a[i].t = a[i].h + 1;
}
else
{
a[i].t = a[i - 1].t + abs(a[i].h - a[i - 1].h) + abs(a[i].l - a[i - 1].l) + 1;
}
a[i].bk = a[i].t + a[i].h;
// cout<<a[i].t<<' '<<a[i].bk<<'\n';
}
else
{
a[i].bk = 0;
a[i].t = 0;
}
}

int ans = 0;
for(int i = 1; i <= H * L; i++)
{
if(!a[i].w) break;
if(T >= a[i].bk)
{
ans += a[i].w;
// cout<<a[i].h<<a[i].l<<a[i].w<<'\n';
}
}
cout<<ans<<'\n';
return 0;
}

問題 E: Trapezoids

時間限制:1Sec記憶體限制:128 MB
提交狀態

題目描述

You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.

An example of a trapezoid

Find the area of this trapezoid.

Constraints
1≦a≦100
1≦b≦100
1≦h≦100
All input values are integers.
h is even.

輸入

The input is given from Standard Input in the following format:
a
b
h

輸出

Print the area of the given trapezoid. It is guaranteed that the area is an integer.

樣例輸入Copy

3
4
2

樣例輸出Copy

7

提示

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2=7.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
long long a,b,c;
cin>>a>>b>>c;
long long ans = (a + b) * c / 2;
cout<<ans<<'\n';
return 0;
}

問題 F: Card Game for Three

時間限制:1Sec記憶體限制:128 MB
提交狀態

題目描述

Alice, Bob and Charlie are playing Card Game for Three, as below:

At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.
The players take turns. Alice goes first.
If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)
If the current player's deck is empty, the game ends and the current player wins the game.
You are given the initial decks of the players. More specifically, you are given three strings SA, SB and SC. The i-th (1≦i≦|SA|) letter in SA is the letter on the i-th card in Alice's initial deck. SB and SC describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints
1≦|SA|≦100
1≦|SB|≦100
1≦|SC|≦100
Each letter in SA, SB, SC is a, b or c.

輸入

The input is given from Standard Input in the following format:
SA
SB
SC

輸出

If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.

樣例輸入Copy

aca
accc
ca

樣例輸出Copy

A

提示

The game will progress as below:
Alice discards the top card in her deck, a. Alice takes the next turn.
Alice discards the top card in her deck, c. Charlie takes the next turn.
Charlie discards the top card in his deck, c. Charlie takes the next turn.
Charlie discards the top card in his deck, a. Alice takes the next turn.
Alice discards the top card in her deck, a. Alice takes the next turn.
Alice's deck is empty. The game ends and Alice wins the game.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
string a,b,c; cin>>a>>b>>c;
// cout<<a<<b<<c;
int la = a.size();
int lb = b.size();
int lc = c.size();
// cout<<la<<lb<<lc;
stack <char> sa; sa.push('d');
stack <char> sb; sb.push('d');
stack <char> sc; sc.push('d');

for(int i = la - 1; i >= 0; i--) sa.push(a[i]);
for(int i = lb - 1; i >= 0; i--) sb.push(b[i]);
for(int i = lc - 1; i >= 0; i--) sc.push(c[i]);
// cout<<sa.size()<<sb.size()<<sc.size();

char s = sa.top();sa.pop();
// cout<<s;
while((!sa.empty()) && (!sb.empty()) && (!sc.empty()))
{
if(s == 'a')
{
s = sa.top();
sa.pop();
}
if(s == 'b')
{
s = sb.top();
sb.pop();
}
if(s == 'c')
{
s = sc.top();
sc.pop();
}
}

if(sa.empty()) cout<<'A'<<'\n';
if(sb.empty()) cout<<'B'<<'\n';
if(sc.empty()) cout<<'C'<<'\n';

return 0;
}

問題 K: Do You Know Your ABCs?

時間限制:1Sec記憶體限制:128 MB
提交狀態

題目描述

Farmer John's cows have been holding a daily online gathering on the "mooZ" video meeting platform. For fun, they have invented a simple number game to play during the meeting to keep themselves entertained.
Elsie has three positive integers A, B, and C (A≤B≤C). These integers are supposed to be secret, so she will not directly reveal them to her sister Bessie. Instead, she gives Bessie seven (not necessarily distinct) integers in the range 1…10^9, claiming that they are A, B, C, A+B, B+C, C+A, and A+B+C in some order.

Given a list of these seven numbers, please help Bessie determine A, B, and C. It can be shown that the answer is unique.

輸入

The only line of input consists of seven space-separated integers.

輸出

Print A, B, and C separated by spaces.

樣例輸入Copy

2 2 11 4 9 7 9

樣例輸出Copy

2 2 7

提示

Test cases 2-3 satisfy C≤50.
Test cases 4-10 satisfy no additional constraints.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
long long a[10];
for(int i = 1; i <= 7; i++) cin>>a[i];

sort(a + 1, a + 1 + 7);

long long a1; a1 = a[1];

long long b = a[7] - a[1]; int vis;
for(int i = 1; i <= 7; i++)
{
if(a[i] == b)
{
vis = i;
break;
}
}

for(int i = 2; i <= vis - 1; i++)
{
for(int j = 2; j <= vis - 1; j++)
{
if(i == j) continue;
if(a[i] + a[j] == b)
{
cout<<a1<<' '<<a[i]<<' '<<a[j]<<'\n';
return 0;
}
}
}

return 0;
}

問題 L: Daisy Chains

時間限制:1Sec記憶體限制:128 MB
提交狀態

題目描述

Every day, as part of her walk around the farm, Bessie the cow visits her favorite pasture, which has N flowers (all colorful daisies) labeled 1…N lined up in a row (1≤N≤100). Flower i has pi petals (1≤pi≤1000).
As a budding photographer, Bessie decides to take several photos of these flowers. In particular, for every pair of flowers (i,j) satisfying 1≤i≤j≤N, Bessie takes a photo of all flowers from flower i to flower j (including i and j).

Bessie later looks at these photos and notices that some of these photos have an "average flower" -- a flower that has P petals, where P is the exact average number of petals among all flowers in the photo.

How many of Bessie's photos have an average flower?

輸入

The first line of input contains N. The second line contains N space-separated integers p1…pN.

輸出

Please print out the number of photos that have an average flower.

樣例輸入Copy

4
1 1 2 3

樣例輸出Copy

6

提示

Every picture containing just a single flower contributes to the count (there are four of these in the example). Also, the (i,j) ranges (1,2) and (2,4) in this example correspond to pictures that have an average flower.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

double a[105] = {0};
double b[105] = {0};

int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
int n; cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>b[i];
a[i] = a[i - 1] + b[i];
}

double t;
long long ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = i; j <= n; j++)
{
t = (a[j] - a[i - 1]) / (j - i + 1);
for(int k = i; k <= j; k++)
{
if(b[k] == t)
{
ans++;
break;
}
}
}
}
cout<<ans<<'\n';

return 0;
}