标签:bestcoder
比赛链接:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=604
1 5
2
#include <cstdio>
#define ll long long
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
ll n;
scanf("%I64d", &n);
int cnt = 0;
bool flag = true;
while(n != 0)
{
if((n & 1) ^ 0)
{
if(flag)
cnt ++;
flag = false;
}
else
flag = true;
n >>= 1;
}
printf("%d\n", cnt);
}
}3 2 3 2 1 1 2 1 3
1 3HintYou shouldn‘t print any space in each end of the line in the hack data.
#include <cstdio>
#include <cstring>
int const MAX = 1005;
int dp[MAX][MAX];
int a[MAX];
int main()
{
int n, q;
scanf("%d %d", &n, &q);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
memset(dp, 0, sizeof(dp));
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
dp[i][j] += (dp[i][j - 1] + (a[i] > a[j] ? 1 : 0));
for(int j = n; j > 0; j--)
for(int i = j; i > 0; i--)
dp[i][j] += dp[i + 1][j];
while(q--)
{
int l, r;
scanf("%d %d", &l, &r);
printf("%d\n", dp[l][r]);
}
}标签:bestcoder
原文地址:http://blog.csdn.net/tc_to_top/article/details/46576591