题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6533
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 776 Accepted Submission(s): 74
Problem Description
You need to construct a full n-ary tree(n叉树) with m layers.All the edges in this tree have a weight.But this weight cannot be chosen arbitrarily you can only choose from set S,the size of S is k,each element in the set can only be used once.Node 0 is the root of tree.
We use d(i) for the distance from root to node i.Our goal is to minimize the following expression:
min∑i=0Nd(i)
Please find the minimum value of this expression and output it.Because it may be a big number,you should output the answer modul p.
Input
The input file contains 2 lines.
The first line contains 4 integers,these respectively is k,m,n,p。(2 ≤ k ≤200000,2 ≤ p≤ 1015)
The second line contains k integers,represent the set S,the elements in the set guarantee less than or equal to 1015.
We guarantee that k is greater than or equal to the number of edges.
Output
The output file contains an integer.represent the answer.
Sample Input
5 2 3 10
1 2 3 4 5
Sample Output
6
代码:
#include
#define inf 0x3f3f3f3f
#define llinf 1ll<<60
using namespace std;
typedef long long ll;
ll read() {
ll x = 0;
ll ch = getchar();
while (ch < '0' || ch > '9') {
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ll)(ch - '0');
ch = getchar();
}
return x;
}
void out(ll a) {
if (a < 0) {
putchar('-');
a = -a;
}
if (a >= 10) {
out(a / 10);
}
putchar(a % 10 + '0');
}
ll a[200010];
ll num[2000];
ll sum[200010];
ll tot[2000];
int main() {
ll n, m, k;
ll p;
while(~scanf("%lld%lld%lld%lld", &k, &m, &n, &p)) {//n叉 m层
ll cnt = 0, t = 1, ans = 0;
sum[0] = 0;
for (ll i = 1; i <= k; i++) {
a[i] = read();
sum[i] = sum[i-1] + a[i];
}
num[1] = 0;
tot[2] = 1;
for (ll i = 2; i <= m; i++) {
t *= n;
cnt += t;
num[i] = num[i-1] + t;//到当前层有多少条边
tot[i+1] = tot[i] + t;//当前层每条边需要使用多少次
}
sort(a+1, a+k+1);
for (ll i = 1; i <= cnt; i++) {
sum[i] = (sum[i-1] + a[i]) % p;
}
for (ll i = 2; i <= m; i++) {
ans = (ans + ((((sum[num[i]] - sum[num[i-1]] + p) % p)) * tot[m-i+2]) % p) % p;
}
out(ans);
putchar('\n');
}
return 0;
}
/*
13 3 3 10000
1 2 3 4 5 6 7 8 9 10 11 12 13
*/
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6536
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 173 Accepted Submission(s): 47
Problem Description
You have a string of lowercase letters.You need to find as many sequence “xtCpc” as possible.But letters in the same position can only be used once。
Input
The input file contains two lines.
The first line is an integer n show the length of string.(1≤n≤2×105)
The second line is a string of length n consisting of lowercase letters and uppercase letters.
Output
The input file contains an integer show the maximum number of different subsequences found.
Sample Input
10
xtCxtCpcpc
Sample Output
2
代码:
#include
using namespace std;
typedef long long LL;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _rep(n,m,i) for (int i = n; i <= m; i++)
#define _for(n,m,i) for (int i = n; i < m; i++)
#define ff first
#define ss second
#define It iterator
#define me(a) memset(a, 0, sizeof(a))
inline int read() {
int x = 0;
char s = getchar();
while(s < '0' || s > '9') s = getchar();
while(s >= '0' && s <= '9') x = x * 10 + s - '0', s = getchar();
return x;
}
LL a[5];
int main() {
string s;
int n;
while(cin >> n >> s) {
memset(a,0,sizeof(a));
_for(0,n,i) {
if(s[i] == 'x')
a[0]++;
if(s[i] == 't')
if(a[0] > a[1])
a[1]++;
if(s[i] == 'C')
if(a[1] > a[2])
a[2]++;
if(s[i] == 'p')
if(a[2] > a[3])
a[3]++;
if(s[i] == 'c')
if(a[3] > a[4])
a[4]++;
}
cout << a[4] << endl;
}
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6542
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 43 Accepted Submission(s): 23
Problem Description
Mahjong is a board game with a long history. But Mahjong has different rules in different city.
A deck of mahjong consists of 136 cards. It contains 1-9 card in three suits,and Seven kinds of word card("dong","nan","xi","bei",“zhong”,"fa","bai"),there are 4 same cards for each kind of card in a deck of mahjong .
In a mysterious country, the rules of mahjong are very simple.In the game,each Player has 14 cards.There are only two ways people can win the game:
1. shisanyao:You should have all 1 and 9 card in three suits and seven kinds of word card at the same time,and an extra card with any kind of 1 and 9 or word.
2. jiulianbaodeng:Firstly,You should make sure that you have the same suit in your hand.Secondly, for card "1" and card "9",you should have at least three . but for card "2" to card "8",at least one.For example, both "11112345678999" and "11122345678999" can win the game.
Now you know a player's 14 cards. Please judge which card type he can use to win the game.
Input
The input file contains 14 lines.Each line has a string representing a card.
For three suits of card "1" to card "9",We use two characters for the type,the first character a is number 1 to 9,and the second character b represents the suit.(a∈{1,2,3,4,5,6,7,8,9},b∈{s,p,w})
For the word cards,as shown in the description,we use full spelling pinyin represent them.
Output
If player ‘s card meet the “shisanyao” condition, you should output "shisanyao!".
If player ‘s card meet the “jiulianbaodeng” condition, you should output "jiulianbaodeng!".
Otherwise,you should output "I dont know!".
Sample Input
1w
5w
2w
6w
5w
9w
9w
7w
1w
3w
9w
4w
1w
8w
Sample Output
jiulianbaodeng!
代码:
#include
#define inf 0x3f3f3f3f
#define llinf 1ll<<60
using namespace std;
typedef long long ll;
int read() {
int x = 0, f = 1;
int ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (int)(ch - '0');
ch = getchar();
}
return x * f;
}
void out(ll a) {
if (a < 0) {
putchar('-');
a = -a;
}
if (a >= 10) {
out(a / 10);
}
putchar(a % 10 + '0');
}
string s[15], card[7] = {"dong","nan","xi","bei","zhong","fa","bai"};
map mp;
set shi;
string ss = "1s1p1w9s9p9wdongnanxibeizhongfabai";
int cnt;
char ch;
int main() {
cnt = 0;
int flag = 0, p = 0;
for (int i = 1; i < 15; i++) {
cin >> s[i];
if(ss.find(s[i]) != string::npos) {
shi.insert(s[i]);
p++;
}
if (s[i][0] >= '1' && s[i][0] <= '9')mp[s[i][0]-'0']++;
else
flag = 1;
if (i == 1) {
ch = s[i][1];
cnt = 1;
} else {
if (s[i][1] != ch) cnt++;
}
}
for (int i = 2; i <= 8; i++) {
if (mp[i] < 1) {
flag = 1;
break;
}
}
if (cnt == 1 && mp[1] >= 3 && mp[9] >= 3 && flag == 0) cout << "jiulianbaodeng!" << endl;
else if (shi.size() == 13 && p == 14) cout << "shisanyao!" << endl;
else
cout << "I dont know!" << endl;
return 0;
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6543
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 67 Accepted Submission(s): 41
Problem Description
Do you feel weird when reading the problem title? You can understand word meanning correctly even if its spelling is wrong.
According to research, if the initial and last letter of the word are right, and just swap the others, human can correct the spelling of the word automatically.
Now, giving you a word and its correct spelling, can you correct it automatically?
Input
The input contains several test cases.
Each test case consists of one line with two strings, each string only contains lowercase letter, and its length is no more than 20.
Output
Output "Equal" when the two strings are same; output "Yes" when you can correct it, otherwise outoput "No".
Sample Input
raed read
it it
croretcly correctly
raed dear
Sample Output
Yes
Equal
Yes
No
代码:
#include
#define inf 0x3f3f3f3f
#define llinf 1ll<<60
using namespace std;
typedef long long ll;
int read() {
int x = 0, f = 1;
int ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (int)(ch - '0');
ch = getchar();
}
return x * f;
}
void out(ll a) {
if (a < 0) {
putchar('-');
a = -a;
}
if (a >= 10) {
out(a / 10);
}
putchar(a % 10 + '0');
}
bool chilk(string s, string t) {
sort(s.begin(), s.end());
sort(t.begin(),t.end());
return s == t;
}
int main() {
string s, t;
while(cin >> s>> t) {
if(s == t) {
cout << "Equal\n";
}
else if(chilk(s,t)) {
if(s[0] == t[0] && s[s.size() - 1] == t[t.size() - 1]) {
cout << "Yes\n";
}
else cout << "No\n";
}
else cout << "No\n";
}
return 0;
}
弱校没能参加现场赛,只能打打重现赛,还只能做出4题来,唉