(1)问题描述:Given the history of a user's activities in CodeChef and other relevant information regarding the new Laddu Accrual System, how many months can he/she redeem laddus?
(2)要点:题目很长但很水
(3)代码:
#include <stdio.h>
#include <assert.h>
#include <string.h>
int main()
{
static const size_t buff_size = 100;
char buff[buff_size] = { 0 };
unsigned int nCases = 0;scanf("%d",&nCases);
for(unsigned int iCases = 1;iCases <= nCases;++iCases)
{
unsigned int n = 0,v = 0;scanf("%d%s",&n,buff);
unsigned int ucost = 200,sum = 0;
if(0 != strcmp(buff,"INDIAN")) ucost = 400;
for(unsigned int i = 0;i < n;++i)
{
scanf("%s",buff);
if(0 == strcmp(buff,"CONTEST_WON"))
{
scanf("%d",&v);
sum += 300 + ((v <= 20)?(20-v):0);
}
else if(0 == strcmp(buff,"TOP_CONTRIBUTOR"))
{
sum += 300;
}
else if(0 == strcmp(buff,"BUG_FOUND"))
{
scanf("%d",&v);
sum += v;
}
else if(0 == strcmp(buff,"CONTEST_HOSTED"))
{
sum += 50;
}
else
{
assert(0);
}
}
printf("%u\n",sum/ucost);
}
return 0;
}
(1)问题描述:There are ten balls and five colors. There are two balls for each color. Each ball weighs 1kg, except for two balls of the same color, which each weights 2kg. Your task is to determine which colored balls are heavier. You can use a weighing scale which measures the exact difference in the weights of the objects between its pans. Your score is determined by the number of times you used the scale. (The fewer times, the higher score.)
(2)要点:称量一次,左边放1 2 2,右边放3 4 4,如果返回1,则是1重;返回2则是2重;返回-1则是3重;返回-2则是4重;返回0则是5重
(3)代码:
#include <stdio.h>
#include <assert.h>
#include <string.h>
int main()
{
printf("1\n");fflush(stdout);
printf("3 1 2 2\n");fflush(stdout);
printf("3 3 4 4\n");fflush(stdout);
int ret = 0;scanf("%d",&ret);
if(0 == ret) { printf("2\n5\n");fflush(stdout); }
else if(1 == ret) { printf("2\n1\n");fflush(stdout); }
else if(2 == ret) { printf("2\n2\n");fflush(stdout); }
else if(-1 == ret) { printf("2\n3\n");fflush(stdout); }
else if(-2 == ret) { printf("2\n4\n");fflush(stdout); }
else { assert(0); }
return 0;
}
(1)问题描述:There are N trees. The initial height of the ith tree is H_i meters, and the height increases R_i meters per month.A tree with heights lower than L cannot be cut. What is the fewest number of months before the Chef can cut W meters of height of wood?
(2)要点:二分,注意L > W的情况
(3)代码:
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <vector>
using std::vector;
struct data_t
{
public:
unsigned int height;
unsigned int rate;
};
class ForestGathering
{
private:
unsigned long long _goal;
unsigned long long _minl;
public:
ForestGathering(unsigned long long w,unsigned long long l):_goal(w),_minl(l) { ; }
public:
bool operator()(const data_t* data,size_t size,unsigned long long p)
{
unsigned long long sum = 0;
for(size_t i = 0;i < size;++i)
{
unsigned long long v = p*data[i].rate + data[i].height;
if(v < _minl) continue;
if(v >= _goal) return true;
sum += v;
if(sum >= _goal) return true;
}
return false;
}
};
template<class T,class Pred> unsigned long long binary_min(const T* data,size_t size,unsigned long long lo,unsigned long long hi,Pred pred)
{
if(pred(data,size,lo)) return lo;
assert(pred(data,size,hi));
for(;lo + 1 < hi;)
{
unsigned long long mid = (lo + hi)/2;
bool ret = pred(data,size,mid);
if(ret) hi = mid;
else lo = mid;
}
return lo + 1;
}
int main()
{
unsigned long long n = 0,w = 0,l = 0;
scanf("%lld%lld%lld",&n,&w,&l);
//scanf("%I64d%I64d%I64d",&n,&w,&l);
ForestGathering slover(w,l);
vector<data_t> data(n);
unsigned long long maxr = 0;
for(unsigned int i = 0;i < n;++i)
{
scanf("%d%d",&data[i].height,&data[i].rate);
if(data[i].rate > maxr) maxr = data[i].rate;
}
unsigned long long hi = w/maxr + 1;
if(w < l) hi = l/maxr + 1;
unsigned long long ans = binary_min<data_t,ForestGathering>(&data[0],n,0,hi,slover);
printf("%llu\n",ans);
//printf("%I64u\n",ans);
return 0;
}
(1)问题描述:There are N dogs numbered from 1 to N in a line. A ball will be pass around. Initially, dog s has the ball.A dog with the ball can pass it to another dog. With the pass strength of x, dog i can pass the ball to dog i - x or dog i + x (provided such dog/s exist).There will be M passes of the ball, and the pass strength of the jth pass is A_j.For each dog, how many ways are there for the ball to end up at that dog? Output your answers modulo 10^9 + 7.
(2)要点:动态规划,dps[curr][i] = dps[prev][i-x] + dps[prev][i+x]
(3)代码:
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <vector>
using std::vector;
int main()
{
static const unsigned int module = 1000000007;
unsigned int nCases = 0;scanf("%d",&nCases);
for(unsigned int iCases = 1;iCases <= nCases;++iCases)
{
unsigned int n = 0,m = 0,s = 0;scanf("%d%d%d",&n,&m,&s);
vector<unsigned int> data(m,0);
for(unsigned int i = 0;i < m;++i) scanf("%d",&data[i]);
vector<unsigned long long> dps[2];
dps[0].resize(n,0);dps[1].resize(n,0);
size_t prev = 0,curr = 1;
dps[prev][s-1] = 1;
for(unsigned int i = 0;i < m;++i)
{
for(unsigned int k = 0;k < n;++k) dps[curr][k] = 0;
for(unsigned int k = 0;k < n;++k)
{
int dst1 = (int)k - data[i];
int dst2 = (int)k + data[i];
if(dst1 >= 0) { dps[curr][dst1] += dps[prev][k];dps[curr][dst1] %= module; }
if(dst2 < n) { dps[curr][dst2] += dps[prev][k];dps[curr][dst2] %= module; }
}
prev = 1 - prev;curr = 1 - curr;
}
for(unsigned int i = 0;i < n;++i) printf("%d ",(unsigned int)(dps[prev][i]));
printf("\n");
}
return 0;
}
(1)问题描述:
(2)要点:预计算1000000000内的Fibonacci数,然后遍历即可
(3)代码:
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <vector>
#include <set>
#include <map>
using std::vector;
using std::set;
using std::map;
unsigned int slove_small(const vector<unsigned int>& data,unsigned int module,unsigned int goal,unsigned int maxi,unsigned int remain)
{
if(0 == goal && 0 == remain) return 1;
if(0 == goal || 0 == remain) return 0;
unsigned int ans = 0;
for(unsigned int i = maxi;i != (unsigned int)(-1);--i)
{
unsigned long long sum = data[i];sum *= remain;
if(sum < goal) break;
if(goal < data[i]) continue;
ans += slove_small(data,module,goal-data[i],i,remain-1);
ans %= module;
}
return ans;
}
int main()
{
static const unsigned int module = 1000000007;
static const unsigned int maxv = 1000000000;
vector<unsigned int> Chefonacci;
Chefonacci.push_back(1);Chefonacci.push_back(2);
for(;;)
{
size_t size = Chefonacci.size();
unsigned int v = Chefonacci[size-1] + Chefonacci[size-2];
if(v > maxv) break;
Chefonacci.push_back(v);
}
unsigned int nCases = 0;scanf("%d",&nCases);
for(unsigned int iCases = 1;iCases <= nCases;++iCases)
{
unsigned int x = 0,n = 0;scanf("%d%d",&x,&n);
printf("%u\n",slove_small(Chefonacci,module,x,Chefonacci.size()-1,n));
}
return 0;
}
(1)问题描述:
(2)要点:
(3)代码:
(1)问题描述:
(2)要点:
(3)代码:
(1)问题描述:
(2)要点:
(3)代码: