Description |
Kim是一个掌控时间的大师。不同于一般人,他习惯使用秒来计算时间。如果你问他现在是几点,他会告诉你现在是今天的xxxx秒。Mik想要考考Kim。他想知道从某一天的00:00:00开始,经过s秒后是哪一天。但是Mik不会计算答案,他需要你的帮助。 注意:我们认为一天从00:00:00开始,到23:59:59结束。00:00:00经过1秒后是00:00:01;从00:00:00开始,加86400(60*60*24)秒后就是下一天的00:00:00. |
Input |
第一行一个整数T表示数据组数。 接下来T行,每行一个日期yyyy-MM-dd,接下来一个整数s表示s秒。 |
Output |
对于每个输入,输出一行yyyy-MM-dd 表示答案。对于不足两位的数要补齐前导0。 |
Sample Input |
3 2016-12-10 1000 2016-02-28 86400 2016-01-01 1000000 |
Sample Output |
2016-12-10 2016-02-29 2016-01-12 |
Hint |
T<=100 s<=2147483647 日期在1800-01-01到2100-01-01之间 闰年的判断: 1.能被4整除且不能被100整除的为闰年. 2.能被400整除的是闰年. |
#include
bool isleap(int y)
{
if(y%4==0&&y%100!=0||y%400==0)
return 1;
return 0;
}
int maxday(int i,int y)
{
if(i==2)
{
if(isleap(y))
return 29;
else
return 28;
}
else if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
return 31;
else
return 30;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int y,m,d,s;
scanf("%d-%d-%d%d",&y,&m,&d,&s);
s=s/86400;
for(int i=1; i<=s; i++)
{
d++;
if(d>maxday(m,y))
{
d-=maxday(m,y);
m++;
}
if(m==13)
y++,m=1;
}
printf("%d-%02d-%02d\n",y,m,d);
}
return 0;
}
Description |
Kim is a college student who love computer games, but unfortunately his school just published a rule that Games should disappear in the campus , that means nobody can play computer games in school, including the students dormitory. However, the student don’t take it seriously, that’s why the manager of the school gets so angry that he decided to go to the dormitory to punish the students. You should know the manager will punish those students who is playing games at the moment he enter the room, and leave immediately if nobody is playing game in this room. Kim is a talented game player , in fact, he is the Carry of a famous Gaming club, so he needs time to practice he’s skills . And luckily , Kim’s roommate Mik is a Geek(also a Kim fan), he hacked the manager’s computer and get the timetable of the manager, and tell Kim when will the manager come to their room tomorrow. A big E-sport Event is around the corner, so Kim list m skills he should practice, each skill takes some time to practice and improve Kim’s skill by some points. You should calculate the max total improvement points Kim can get. Note any skills can be practiced any times , including 0. |
Input |
The first line contains a integer T ( T <= 10 ), then T cases follows. In each case, there are 3 parts of input. The first part contains 3 integers L, n, m in a single line.Range[0, L] is the time Kim decide to practice , n is the times manager would enter his room, m indicate the total number of the skills. The second part contains n integers ti(0 <= ti <= L) in a single line, means the manager would enter his room at ti. Note that ti is giving in the increasing order. The third part has m lines , each line contains two integers ci, vi, means this skill needs ci minutes to practice and can make vi points improvement. L<=500, n<=10, m<=100. |
Output |
For each case, you should output the max points Kim can improve. |
Sample Input |
2 6 1 3 3 2 3 2 4 2 5 6 2 3 2 4 2 3 2 4 2 5 |
Sample Output |
10 15 |
Hint |
Note that Kim will be catch playing games any time in the interval of his practicing, excluded the beginning and the ending of each practice time. Sample 1: Sample 2: |
#include
#include
#define max(a,b) (a>b?a:b)
#define N 500+10
int a[11],vi[101],ci[101],dp[N];
int l,n,m;
void mulpack(int y)
{
int i,j;
for(i=1; i<=m; i++)
for(j=ci[i]; j<=y; j++)
dp[j]=max(dp[j],dp[j-ci[i]]+vi[i]);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,s=0;
scanf("%d%d%d",&l,&n,&m);
for(i=1; i<=n; i++)
scanf("%d",&a[i]);
a[0]=0,a[n+1]=l;
for(i=1; i<=m; i++)
scanf("%d%d",&ci[i],&vi[i]);
for(i=0; i<=n; i++)//分段,求多个多个完全背包
{
memset(dp,0,sizeof(dp));
mulpack(a[i+1]-a[i]);
s+=dp[a[i+1]-a[i]];
}
printf("%d\n",s);
}
return 0;
}
Description |
Kim刚刚学会C语言中的取模运算(mod)。他想要研究一下一个数字A模上一系列数后的结果是多少。帮他写个程序验证一下。 |
Input |
第一行一个整数T代表数据组数。 接下来T组数据,第一行一个整数n,接下来n个数字ai 接下来一行一个整数m,接下来m个数字bi。 |
Output |
对于每个bi,输出bi%a1%a2%...%an 。 |
Sample Input |
1 4 10 9 5 7 5 14 8 27 11 25 |
Sample Output |
4 3 2 1 0 |
Hint |
在C语言中,A mod B 是 a%b 样例解释: 14%10%9%5%7=4 8%10%9%5%7=3 ... 数据范围: 1<=n<=100000 1<=m<=100000 1<=ai<=1000000000 0<=bi<=1000000000 |
#include
#define ll long long int
#define N 100000+10
ll a[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll n,m,k,i;
scanf("%lld",&n);
for(i=1;i<=n;i++)
scanf("%lld",&a[i]);
ll tot=1;
for(i=2;i<=n;i++)//找出单调递减的元素
if(a[i]1)//利用二分法不断地取模
{
ll mid=x+(y-x)/2;
if(a[mid]<=k)
y=mid;
else
x=mid;
}
if(y==n+1)//直到k比所有元素都小
break;
k=k%a[y];
}
printf("%lld\n",k);
}
}
return 0;
}
ps:
中等题。注意到不断取模下去会越来越小,而且一个数模a之后再模b,如果a比b小那么模b就没有意义了。所以对输入的a数组剔除所有没用的数,剩下一个递减的数组。在这个数组上,每次二分找到距离当前x最接近且大于x的数,模上这个数重复这一过程即可。这个过程不会重复很多次。很快这个数就会小于所有的a,这时就获得了答案。(二分还是很重要呀呀)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
下面都是对我来说比较难的题了,先存起来。(待补)
F题Number Game
原题链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2319
Description |
There are n items and two players, Kim and you. For each player and for each item, the value of the item for this player is known. Denote values of the i-th item for the first and the second player as ai and bi correspondingly. Players take the items in turns. Kim starts the game. Kim is greedy: each turn, he chooses the item which has the maximal ai among the remaining items. If there are several such items, he can take any one of them. What is the maximal possible sum of values bi of items taken by the second player that he can guarantee regardless of the first player’s moves? |
Input |
The first line is an integer T, describes the number of tests. Then T tests. Each case contains a single integer n, the number of items. The second line contains n numbers, i-th is equal to ai, the value of the i-th item for Kim. The third line contains n numbers, i-th is equal to bi, the value of the i-th item for the second player. |
Output |
Output a single number: the maximal sum of values bi of items taken by the second player that he can guarantee. |
Sample Input |
1 5 1 2 3 4 5 2 3 4 5 6 |
Sample Output |
8 |
Hint |
1 <= n <= 1000 ai and bi are integers from 1 to 10e9 |
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
ps:
难题。这是一道贪心问题。把数据按ai从大到小排序,ai相同的bi从大到小排序。根据题意a会按照排好的顺序每次拿最大的。那么我们的贪心思路就是每次如果我们可以用当前的bi换下一个会被拿走的bi,从而使得bi的和变大,那我们就交换。这样贪心下去就可以得到答案。具体实现的时候可以用一个堆来动态的获得当前的最大(最小)值。
G题OX
原题链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2320
Description |
Kim喜欢玩井字棋。但是他从来都没有赢过:)Kim非常好奇井字棋是否有一个必胜的策略。 给定一个局面,以及下一步该谁走(o或x),请判断在双方都足够聪明的情况下(双方一直采用最优策略),是否有一个人能够获胜(或者平局)。 |
Input |
第一行一个整数T代表数据组数。 接下来T组数据,每组数据三行,每行三个字符串(o 或 x 或 .) o表示这个位置有一个o x表示这个位置有一个x .表示这个位置是空的 接下来一行一个字符串(o 或 x),表示下一步该这个人走了。 |
Output |
如果x有必胜策略,输出 “x win!”(不含引号)。 如果o有必胜策略,输出 “o win!”(不含引号)。 如果双方在最有策略下只能平局,输出 “tie!” (不含引号)。 |
Sample Input |
2 . . . . o . x x . x . . . . . . . . x o |
Sample Output |
x win! tie! |
Hint |
T <= 10 |
#include
#include
#include
#include
#include
#include
ps:
中等题。博弈搜索。实际上一共9个位置,每个位置3个状态,一共只有3^9=19683种状态。我们可以暴力枚举出所有的状态,做一个搜索即可。对于当前的一个状态,如果其后继状态里存在先手必败的状态,那么这个状态是先手必胜的;如果其后继状态里没有先手必败的状态但有平局状态,那么这个状态是平局态;如果其后继状态里都是先手必胜态,那么当前状态只能是先手必败了
H题Permutation
原题链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2321