M - Candy Sharing Game
Description
Input
Output
Sample Input
Sample Output
Hint
The game ends in a finite number of steps because:
1. The maximum candy count can never increase.
2. The minimum candy count can never decrease.
3. No one with more than the minimum amount will ever decrease to the minimum.
4. If the maximum and minimum candy count are not the same, at least one student with the minimum amount must have their count increase. 这是我的代码,我依旧不知道这是为什么!!!! 被自己蠢死了!
#include <iostream>
using namespace std;
int x[],y[];
void f(int s[],int n,int k)
{
int i,j,a[][];
for(i=;i<n;i++)a[][i]=s[i];
for(j=;;j++){
bool flag=true;
a[j][]=a[j-][]/+a[j-][n-]/;
if(a[j][]%!=)a[j][]++;
for(i=;i<n;i++){
a[j][i]=a[j-][i-]/+a[j-][i]/;
if(a[j][i]%!=)a[j][i]++;
if(flag==true&&a[j][i]!=a[j][])flag=false;
}
if(flag==true){
x[k]=j;
y[k]=a[j][];
break;
}
}
}
int main()
{
int n,k=;
while(cin>>n){
if(n==)break;
int s[],i;
for(i=;i<n;i++)cin>>s[i];
f(s,n,k);
k++;
}
for(int i=;i<k;i++)
cout<<x[i]<<" "<<y[i]<<endl;
//system("pause");
return ;
}
这是正确代码
#include<iostream>
using namespace std;
const int MAXN=;
int a[MAXN];
int main()
{
int n;
int i;
while(cin>>n,n)
{
for(i=;i<n;i++)cin>>a[i];
int res=;
while()
{
for(i=;i<n;i++)
if(a[i-]!=a[i]) break;
if(i>=n) break;
res++;
int temp=a[n-]/;
for(i=n-;i>;i--)
{
a[i]/=;
a[i]+=a[i-]/;
}
a[]/=;
a[]+=temp;
for(i=;i<n;i++)
if(a[i]&) a[i]++;
}
cout<<res<<" "<<a[]<<endl;
}
//system ("pause");
return ;
}
M - Candy Sharing Game的更多相关文章
- POJ - 1666 Candy Sharing Game
这道题只要英语单词都认得,阅读没有问题,就做得出来. POJ - 1666 Candy Sharing Game Time Limit: 1000MS Memory Limit: 10000KB 64 ...
- hdu 1034 Candy Sharing Game
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Candy Sharing Game(模拟搜索)
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Candy Sharing Game(hdoj1034)
Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...
- HDU1034 Candy Sharing Game
Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...
- HDU 1034 Candy Sharing Game (模拟)
题目链接 Problem Description A number of students sit in a circle facing their teacher in the center. Ea ...
- sicily 1052. Candy Sharing Game
Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...
- 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...
- HDU-1034 Candy Sharing Game 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1034 水题 代码 #include <cstdio> #include <algorithm> ...
随机推荐
- 混入模式(max-in)实现继承
混入模式并不是一种复制完整的对象,而是从多个对象中复制出任意的成员并将这些成员组合成一个新的对象. 实现如下: function mix(){ var arg,prop,child = {}; for ...
- DNF(一.YUM已死,DNF代之)
Yum还没学好呢,突然听到已经要被抛弃了.恐慌至极.. 在最新版的Fedora 22 抛弃了Yum包管理器,取而代之的是DNF.. 那么搜搜 Fedora 22 Release Note.. 官方给出 ...
- Tornado web 框架
Tornado web 框架 其实很简单.深度应用 一.简介 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像we ...
- iOS7适配问题
iOS7适配问题 2013-09-28 08:32:37 我来说两句 作者:冻僵的企鹅 收藏 我要投稿 iOS 7发布了,适配问题来了,开发者都忙起来了. 先记一个iOS7 的 ...
- 在Fragment中使用BaiduMap SDK
1:fragment_bshdzh.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...
- cf B. Simple Molecules
http://codeforces.com/contest/344/problem/B #include <cstdio> #include <cstring> using n ...
- windows下wchar_t* 转char*
这个在windows下很常见,常用,留个档. 一般用这个函数: size_t wcstombs( char *mbstr, const wchar_t *wcstr, size_t count ); ...
- 缓存一致性(Cache Coherency)入门(转)
参考原文:http://fgiesen.wordpress.com/2014/07/07/cache-coherency/ 本文是RAD Game Tools程序员Fabian “ryg” Giese ...
- 【转】SecureCRT 实用配置----不错
原文网址:http://blog.csdn.net/ithomer/article/details/9503123 SecureCRT,是一款支持 SSH2.SSH1.Telnet.Telnet/SS ...
- Video.js网页视频播放插件
插件描述:Video.js 是一个通用的在网页上嵌入视频播放器的 JS 库,Video.js 自动检测浏览器对 HTML5 的支持情况,如果不支持 HTML5 则自动使用 Flash 播放器. ...