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> ...
随机推荐
- (二)CodeMirror - 配置项
theme: string theme:'monokai' 引入对应的css, <link rel="stylesheet" href="../theme/mono ...
- mysql对GIS空间数据的支持,包括创建空间索引
CREATE TABLE tb_geo( id INT PRIMARY KEY AUTO_INCREMENT, NAME ) NOT NULL, pnt POINT NOT NULL, SPATIAL ...
- poj3579 二分搜索+二分查找
Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5468 Accepted: 1762 Descriptio ...
- poj 3104 二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12568 Accepted: 3243 Descripti ...
- ueditor 百度编辑器 自定义图片上传路径和格式化上传文件名
今天项目中需要自定义图片上传的保存路径,并且不需要按照日期自动创建存储文件夹和文件名,我的ueditor版本是1.3.6.下面记录一下我配置成功的方法,如果有什么不对的地方欢迎指出,共同学习: 1:我 ...
- 远程调试 Azure 上的 Website
让我们先检查一下使用的 Azure SDK 版本和 Visual Studio 版本.根据MSDN的介绍,Azure 的远程调试功能是在 Azure SDK 2.2 中加入的,所以请确保您的机器上安装 ...
- ASP.NET学习笔记——ASP.NET应用程序
0 剖析ASP.NET应用程序 用户运行ASP.NET应用程序,不是直接运行,而是使用浏览器(比如IE)通过HTTP请求一个特定的URL(如http://www.mysite.com/mypage.a ...
- Linux怎样修改系统时间
修改linux的时间可以使用date指令 修改日期: 时间设定成2009年5月10日的命令如下: #date -s 05/10/2009 修改时间: 将系统时间设定成上午10点18分0秒的命令如下. ...
- DJANGO学习一则
这个WEB框架,可以好好研究,相信很快就会用在工作上的. 相关文件: settings.py """ Django settings for djangoweb proj ...
- bzoj 1912 巡逻(树直径)
Description Input 第一行包含两个整数 n, K(1 ≤ K ≤ 2).接下来 n – 1行,每行两个整数 a, b, 表示村庄a与b之间有一条道路(1 ≤ a, b ≤ n). Ou ...