• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Warm up 16 Choosing Numbers

Choosing Numbers
Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB
Total submit users: 43, Accepted users: 39
Problem 12780 : No special judgement

Problem description

是这个argest,我TM左认右认都认不出来啊,你TM的去泰国做个手术看我能不能认出来!

You regularly play a game with friends, and you’re tired of losing. The goal of the game is to end up with the largest number in your hand at the end. Initially there is a set of unique numbers on the table. At each turn, a player chooses a number from the table and puts it in his hand. Seems simple, right? However, you may be required to discard numbers in your hand. During the game, each number can either be on the table, in a player’s hand, or in a discard pile. When a player chooses a number x from the table, x is compared with all other numbers y that are not on the table (including other players’ hands, your own hand, and those in the discard pile). If x and y have a common factor greater than 1, both are moved to (or remain in) the discard pile. The game ends when all numbers have been chosen from the table.
Input
Each input line describes the set of numbers on the table at the beginning of a game. The line begins with a number 1 ≤ n ≤ 1000. Following this are n unique positive integers, all in the range [2, 2 × 10^9]. These are the n numbers that are initially on the table. There are at most 1000 games in the input. Input ends at end of file.
Output
For each game print the number x from the table such that choosing x guarantees you win the game. Each game given has a unique winning number.
Sample Input
Sample Input 1
2 4 7
4 4 8 15 16
4 2 3 4 8
Sample Output
Sample Output 1
7
15
3
Problem Source
HNU Contest 
Submit   Discuss   Judge Status  Problems  Ranklist 
 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cstdlib>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define maxn 1305
14 #define ll long long
15 #define mod 1000000007
16 #define INF 0x7fffffff
17 #define eps 1e-8
18 int n, m;
19 ll gcd(ll n, ll m){ return m ? gcd(m, n%m) : n; }
20 ll a[maxn];
21 int vis[maxn];
22 int main(){
23     /*int t;
24     scanf("%d", &t);
25     while (t--){
26     scanf("%I64d", &n);
27 
28     }*/
29     ll x, y, x1, x2, y1, y2, s1, s2;
30     while (scanf("%d", &n) != EOF){
31         for (int i = 0; i<n; i++)scanf("%I64d", &a[i]);
32         int flag = 0;
33         memset(vis, 0, sizeof vis);
34         ll ma = -INF;
35         sort(a, a + n);
36         for (int i = n - 1; i >= 0; i--){
37             int t = 0;
38             if (!vis[i]){
39                 for (int j = 0; j < n; j++)
40                 if (i != j){
41                     if (gcd(a[i], a[j]) == 1)t++;
42                     else vis[j] = 1;
43                 }
44                 if (t == n - 1){printf("%I64d\n", a[i]); break;}
45                 else vis[i] = 1;
46             }
47         }
48     }
49     return 0;
50 }
View Code
posted @ 2013-11-04 03:05  HaibaraAi  阅读(215)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3