[编制程序题-蘑菇街] 投球游戏

[编程题-蘑菇街] 任意球游戏

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>Document</title>
</head>
<body>
<form id=”ifm” name=”ifm”>
<table>
<tr>
<td>姓名:</td>
<td><input type=”text” name=”name”
value=”李四”/></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type=”text” name=”age” value=”22″/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type=”password” name=”pwd”
value=”123456″/></td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type=”radio” name=”sex” value=”male” id=”male” checked=””
/>
<label for=”male”>男</label>
<input type=”radio” name=”sex” value=”female” id=”female”/>
<label for=”female”>女</label>
</td>
</tr>
<tr>
<td>地区:</td>
<td>
<select name=”area” id=”area”>
<option value=”锦江区” selected>锦江区</option>
<option value=”金牛区”>金牛区</option>
<option value=”青羊区”>青羊区</option>
</select>
</td>
</tr>
<tr>
<td>爱好</td>
<td>
<input type=”checkbox” id=”move” value=”move” name=”habb”
checked/>
<label for=”move”>电影</label>
<input type=”checkbox” id=”music” value=”music” name=”habb”
checked/>
<label for=”music”>音乐</label>
<input type=”checkbox” id=”basketball” value=”basketball”
name=”habb[]”/>
<label for=”basketball”>篮球</label>
</td>
</tr>
<tr>
<td>个人介绍:</td>
<td><textarea name=”txt” id=”txt” cols=”30″
rows=”二”>WEB前段攻城师</textarea></td>
</tr>
<tr>
<td></td>
<td><input type=”button” value=”提交”
id=”btn”/></td>
</tr>
<tr>
<td><button>123</button></td>
<td></td>
</tr>
</table>
</form>
<script src=”jquery-1.11.1.js”></script>
<script>
function getData(){
var frm = $(‘#ifm’);
var data = frm.serialize();
var arr = data.split(‘&’);
var item,key,value,newData = {};
for(var i = 0; i < arr.length; i++){
item = arr[i].split(‘=’);
key = decodeURI(item[0]);
value = decodeURI(item[1]);
if(key.indexOf(‘[]’)!= -1){
key.replace(‘[]’,”);
if (!newData[key]){
newData[key]=[];
}
newData[key].push(value);
}else{
newData[key]=value;
}
}
return newData;
}
$(‘#btn’).bind(‘click’,function(){
var newdata=getData();
$.post(‘test.php’,newdata,function(){
console.log(‘success’);
});
});
</script>
</body>
</html>

有二个投球游戏。训练场有p个篮筐,编号为0,一…,p-一。每种篮筐下有个袋子,每一种袋子最多装三个篮球。有n个篮球,每种球号码xi 。规则是将数字为xi 的篮球投到xi 除p的余数为编号的袋里。若袋里已有篮球则球弹出行戏停止输出i,不然重复至具备球都投完。输出-1。问游戏最后的出口是哪些?

test.php响应的数额是那样的图片 1

输入描述:
第一行两个整数p,n(2≤p,n≤300)。p为篮筐数,n为篮球数。接着n行为篮球上的数字xi(0≤xi≤1e9)
出口描述:
输出游戏的结果

 

输入例子:
10 5
0
21
53
41
53

 

出口例子:
4

#include<iostream>
#include<set>
using namespace std;
int main()
{
    long p,n;
    while(cin>>p>>n)
    {
        set<long> s;
        int flag=false;
        for(int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            if(flag) continue;
            if(s.find(x%p)==s.end())
                s.insert(x%p);
            else
            {
                cout<<i+1<<endl;
                flag=true;
            }

        }
        if(!flag) cout<<"-1"<<endl;
    }
    return 0;
}