Problem DescriptionBob是个很喜欢数字的孩子,现在他正在研究一个与数字相关的题目,我们知道一个数字的完美度是 把这个数字分解成三个整数相乘A*A*B(0<A<=B)的方法数,例如数字80可以分解成1*1*80,2*2*20 ,4*4*5,所以80的完美度是3;数字5只有一种分解方法1*1*5,所以完美度是1,假设数字x的完美度为d(x),现在给定a,b(a<=b),请你帮Bob求出
S,S表示的是从a到b的所有数字的流行度之和,即S=d(a)+d(a+1)+…+d(b)。
Input
Output
Sample Input
Sample Output#include <cstdio>
#include <cstring>
#define ll long long
ll cal(ll x)
{
ll cnt = 0;
for(ll i = 2; i * i * i <= x; i++)
cnt += x / (i * i) - i + 1;
return x + cnt;
}
int main()
{
ll a, b;
while(scanf("%I64d %I64d", &a, &b) != EOF)
printf("%I64d\n", cal(b) - cal(a - 1));
}
Problem Description
Input
Output
Sample Input
Sample Output
Hint#include <cstdio>
#include <cstring>
#define ll long long
int const MAX = 1e5;
char s[MAX];
ll gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s", s);
int l = strlen(s);
ll len = 1;
ll num = 0;
bool flag = false;
for(int i = 0; i < l; i++)
{
if(s[i] == '.')
{
flag = true;
continue;
}
num = num * 10 + (s[i] - '0');
if(flag)
len *= 10;
}
ll g = gcd(num, len);
printf("%I64d/%I64d\n", num / g, len / g);
}
}
Problem Description
Input
Output
Sample Input
Sample Output#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const MAX = 1e5 + 5;
int re[MAX], fa[MAX];
int n;
int get_num(int v)
{
int cnt = 0;
for(; v; v = fa[v])
cnt += re[v];
return cnt;
}
int main()
{
while(scanf("%d", &n) != EOF)
<span style="font-size:14px;">{
memset(re, 0, sizeof(re));
memset(fa, 0, sizeof(fa));
int sum = 0;
for(int i = 0; i < n - 1; i++)
{
int u, v, w;
scanf("%d %d %d", &u, &v, &w);
fa[v] = u;
re[v] = w;
sum += w;
}
int ma = 0;
for(int i = 2; i <= n; i++)
ma = max(ma, get_num(i));
printf("%d\n", sum - ma);
}
}</span>
Problem Description
Input有多组测试数据。
每组测试数据第一行是一个整数T,代表接下去的例子数。(0<=T<=10)
接下来是T组例子。
每组例子第一行是两个整数N和M。代表迷宫的大小有N行M列(0<=N,M<=1000)。
接下来是一个N*M的迷宫描述。
S代表小明的所在地。
E代表出口,出口只有一个。
.代表可以行走的地方。
!代表岩浆的产生地。(这样的地方会有多个,其个数小于等于10000)
#代表迷宫中的墙,其不仅能阻挡小明前进也能阻挡岩浆的蔓延。
小明携带者宝藏每秒只能向周围移动一格,小明不能碰触到岩浆(小明不能和岩浆处在同一格)。
岩浆每秒会向四周不是墙的地方蔓延一格。
小明先移动完成后,岩浆才会蔓延到对应的格子里。
小明能移动到出口,则小明顺利逃脱。
Output
Sample Input
Sample Output#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int const MAX = 1005;
int const INF = 0x7fffffff;
char map[MAX][MAX];
int tim[MAX][MAX];
bool vis[MAX][MAX];
int n, m;
int sx, sy, ex, ey;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
struct NODE
{
int x, y;
int step;
};
bool ok(int i, int j)
{
if(i >= 0 && j >= 0 && i < n && j < m)
return true;
return false;
}
void BFS1()
{
NODE yj;
queue <NODE> q;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if(map[i][j] == '!')
{
yj.x = i;
yj.y = j;
yj.step = 0;
tim[i][j] = 0;
q.push(yj);
}
}
}
while(!q.empty())
{
NODE now = q.front(), t;
q.pop();
//printf("now.x = %d now.y = %d now.step = %d\n", now.x, now.y, now.step);
for(int i = 0; i < 4; i ++)
{
t.x = now.x + dx[i];
t.y = now.y + dy[i];
t.step = now.step + 1;
if(ok(t.x, t.y) && t.step < tim[t.x][t.y])
{
tim[t.x][t.y] = t.step;
q.push(t);
}
}
}
return;
}
bool BFS2()
{
memset(vis, false, sizeof(vis));
NODE st;
st.x = sx;
st.y = sy;
vis[sx][sy] = true;
st.step = 0;
queue <NODE> qq;
qq.push(st);
while(!qq.empty())
{
NODE now = qq.front(), t;
qq.pop();
if(now.x == ex && now.y == ey && t.step <= tim[t.x][t.y])
return true;
for(int i = 0; i < 4; i++)
{
t.x = now.x + dx[i];
t.y = now.y + dy[i];
t.step = now.step + 1;
if(t.x == ex && t.y == ey && t.step <= tim[t.x][t.y])
return true;
if(ok(t.x, t.y) && !vis[t.x][t.y] && t.step < tim[t.x][t.y])
{
vis[t.x][t.y] = true;
qq.push(t);
}
}
}
return false;
}
int main()
{
int T;
while(scanf("%d", &T) != EOF)
{
while(T--)
{
scanf("%d %d", &n, &m);
if(n == 0 || m == 0)
{
printf("No\n");
continue;
}
for(int i = 0; i < n; i++)
{
scanf("%s", map[i]);
for(int j = 0; j < m; j++)
{
tim[i][j] = INF;
if(map[i][j] == 'S')
{
sx = i;
sy = j;
}
if(map[i][j] == 'E')
{
ex = i;
ey = j;
}
if(map[i][j] == '#')
tim[i][j] = 0;
}
}
BFS1();
printf("%s\n", BFS2() ? "Yes" : "No");
}
}
}
Problem Description
Input
Output
Sample Input
Sample Output#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const MAX = 1e5;
char s[MAX];
int idx[MAX];
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int x, y;
scanf("%d %d",&x, &y);
scanf("%s", s);
int len = strlen(s), cnt = 0;
for(int i = len - 1; i >= 0; i--)
if(s[i] == '1')
idx[cnt ++] = i;
int ans = 0, now = 0;
for(int i = 0; i < cnt; i++)
if(s[i] == '0')
ans += min(y, x * (idx[now ++] - i));
printf("%d\n", ans);
}
}原文地址:http://blog.csdn.net/tc_to_top/article/details/45481713