A: 模拟26进制加法即可
/*************************************************************************
> File Name: cf-293-a.cpp
> Author: ALex
> Mail: [email protected]
> Created Time: 2015年02月25日 星期三 13时40分05秒
************************************************************************/
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
string A, B;
int main ()
{
while (cin >> A >> B)
{
int len = A.length();
int c = 1;
for (int i = len - 1; i >= 0; --i)
{
if (!c)
{
break;
}
if (A[i] == ‘z‘ && c)
{
A[i] = ‘a‘;
}
else if (c)
{
++A[i];
c = 0;
}
}
if (A >= B)
{
cout << "No such string" << endl;
continue;
}
cout << A << endl;
}
return 0;
}
B:注意读题仔细,另外要先计算第一个答案,标记好,再去算第二个答案
/*************************************************************************
> File Name: cf-293-b.cpp
> Author: ALex
> Mail: [email protected]
> Created Time: 2015年02月25日 星期三 01时01分17秒
************************************************************************/
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
const int N = 200100;
char s[N], t[N];
bool vis[N];
int num[130];
int main ()
{
while (~scanf("%s%s", s, t))
{
int ans1 = 0, ans2 = 0;
int len = strlen (t);
memset (num, 0, sizeof(num));
memset (vis, 0, sizeof(vis));
for (int i = 0; i < len; ++i)
{
++num[t[i]];
}
len = strlen (s);
for (int i = 0; i < len; ++i)
{
if (num[s[i]] > 0)
{
vis[i] = 1;
++ans1;
--num[s[i]];
}
}
for (int i = 0; i < len; ++i)
{
if (!vis[i])
{
if (s[i] >= ‘A‘ && s[i] <= ‘Z‘)
{
if (num[s[i] - ‘A‘ + ‘a‘] > 0)
{
++ans2;
--num[s[i] - ‘A‘ + ‘a‘];
}
}
else
{
if (num[s[i] - ‘a‘ + ‘A‘] > 0)
{
++ans2;
--num[s[i] - ‘a‘ + ‘A‘];
}
}
}
}
printf("%d %d\n", ans1, ans2);
}
return 0;
}
C:水题模拟题
/*************************************************************************
> File Name: cf-293-c.cpp
> Author: ALex
> Mail: [email protected]
> Created Time: 2015年02月25日 星期三 14时36分58秒
************************************************************************/
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
const int N = 100100;
vector <int> scr[N];
int arr[N];
int at[N];
int ord[N];
int main ()
{
int n, m, k;
int app;
while (~scanf("%d%d%d", &n, &m, &k))
{
for (int i = 1; i <= n; ++i)
{
scr[i].clear();
}
for (int i = 1; i <= n; ++i)
{
int pos = i / k + ((i % k) ? 1 : 0);
scanf("%d", &app);
at[app] = pos;
scr[pos].push_back (app);
if (i % k)
{
ord[app] = i % k - 1;
}
else
{
ord[app] = k - 1;
}
}
LL ans = 0;
for (int i = 1; i <= m; ++i)
{
scanf("%d", &app);
ans += at[app];
int s = at[app];
int cur = ord[app];
if (s == 1 && cur == 0)
{
continue;
}
if (cur == 0)
{
int size = scr[s - 1].size();
int &a = scr[s - 1][size - 1];
int &b = scr[s][cur];
at[a] = s;
at[b] = s - 1;
ord[a] = 0;
ord[b] = size - 1;
swap (a, b);
}
else
{
int &a = scr[s][cur - 1];
int &b = scr[s][cur];
ord[a] = cur;
ord[b] = cur - 1;
swap (a, b);
}
}
printf("%I64d\n", ans);
}
D:水题概率dp
设dp[i][j] i秒时,车厢里j个人的概率
/*************************************************************************
> File Name: cf-293-d.cpp
> Author: ALex
> Mail: [email protected]
> Created Time: 2015年02月25日 星期三 01时59分30秒
************************************************************************/
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
double dp[2010][2010];
int n, t;
double p;
int main ()
{
while (~scanf("%d%lf%d", &n, &p, &t))
{
memset (dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 1; i <= t; ++i)
{
dp[i][0] = dp[i - 1][0] * (1 - p);
int e = min (n, i);
for (int j = 1; j <= e; ++j)
{
if (j < e)
{
dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p);
}
else
{
dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j];
}
}
}
double ans = 0;
for (int i = 0; i <= t; ++i)
{
ans += dp[t][i] * i;
}
printf("%.10f\n", ans);
}
return 0;
}
时间: 2024-11-05 05:25:50