[NOIP-P1028]吉祥数

题目描述(Description)

为了迎接圣诞,信息学兴趣小组的同学们在辅导老师的领导下,举办了一个盛大的晚会,晚会的第一项内容是做游戏:猜数。老师给每个同学发一张卡片,每张卡片上都有一个编号(此编号为非负数,且小于255),每个编号互不相同。老师制定了以下的游戏规则:第一轮,每个同学将自己编号的各位数字进行平方后再相加得到一组数,编号在这组数中出现的同学淘汰出局;第二轮,余下的同学再将自己编号的各位数字进行立方相加得到一组新数,编号在这组数中出现的同学再淘汰出局;第三轮,余下的同学再将编号的各位数字进行4次相加得到一组新数,编号在这组数中出现的同学再淘汰出局,依此类推,经过n轮后,仍留下来的同学将获得圣诞特别礼物,卡片上的数即2009年吉祥数。(假定班级人数不超过200人)

输入格式(Format Input)

第1行为1个正整数n(n<8),表示有n轮游戏
第二行是卡片上互不相同的编号,以空格隔开。

输出格式(Format Output)

输出一行,为剩下来的各个吉祥数,按从小到大顺数输出,每两个数之间有一个空格。

输入样例(Sample Input)

1
24 123 2 12 20 14 4 6 36 72

输出样例(Sample Output)

2 6 12 24 72 123

思路:

每轮相当于每位乘以(n+1)次幂,都加起来,如果不符合要求的先别急着改,因为它还可以淘汰别人。

Code

#include<bits/stdc++.h>
using namespace std;
int x,a[1001],b[1001],n;
int f(int x,int y)
{
    int ans=0;
    while(x)
    {
        ans+=pow(x%10,y);
        x/=10;
    }
    return ans;
}
int main()
{
    cin>>n;
    while(scanf("%d",&x)!=EOF)
    {
        a[x]=1;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<255;j++)
        {
            if(a[j])
            {
                int t=f(j,i+1);
                if(t<255)    b[t]=1;
            }
        }
        for(int k=0;k<255;k++)
        {
            if(a[k]&&b[k])    a[k]=0;
        }
        memset(b,0,sizeof(b));
    }
    for(int i=1;i<255;i++)
    {
        if(a[i])    cout<<i<<" ";
    }
    return 0;
 }

Hoof, Paper, Scissors【USACO 2017 January Contest, Bronze】

题目描述(Description)


You have probably heard of the game “Rock, Paper, Scissors”. The cows like to play a similar game they call “Hoof, Paper, Scissors”.

The rules of “Hoof, Paper, Scissors” are simple. Two cows play against each-other. They both count to three and then each simultaneously makes a gesture that represents either a hoof, a piece of paper, or a pair of scissors. Hoof beats scissors (since a hoof can smash a pair of scissors), scissors beats paper (since scissors can cut paper), and paper beats hoof (since the hoof can get a papercut). For example, if the first cow makes a “hoof” gesture and the second a “paper” gesture, then the second cow wins. Of course, it is also possible to tie, if both cows make the same gesture.

Farmer John watches in fascination as two of his cows play a series of N games of “Hoof, Paper, Scissors” (1≤N≤100). Unfortunately, while he can see that the cows are making three distinct types of gestures, he can’t tell which one represents “hoof”, which one represents “paper” and which one represents “scissors” (to Farmer John’s untrained eye, they all seem to be variations on “hoof”…)

Not knowing the meaning of the three gestures, Farmer John assigns them numbers 1, 2, and 3. Perhaps gesture 1 stands for “hoof”, or maybe it stands for “paper”; the meaning is not clear to him. Given the gestures made by both cows over all N games, please help Farmer John determine the maximum possible number of games the first cow could have possibly won, given an appropriate mapping between numbers and their respective gestures.

你可能听说过“石头、布、剪刀”游戏。奶牛喜欢玩一种类似的游戏,他们称之为“蹄子、布、剪刀”。

游戏的规则很简单。两头母牛互相玩耍。他们都数到三,然后每个人同时做一个手势,表示一只蹄子、一张纸或一把剪刀。蹄子打败剪刀(因为蹄子可以打碎剪刀),剪刀打败纸(因为剪刀可以剪纸),纸打败蹄子(因为纸包裹蹄子)。例如,如果第一头牛做出“蹄子”手势,第二头牛做出“纸”手势,那么第二头牛获胜。当然,如果两头母牛做出相同的姿势,也可以打平局。

农夫约翰着迷地看着他的两只母牛玩一系列的“蹄子、布、剪刀”游戏(1)≤N≤100). 不幸的是,虽然他能看到奶牛在做三种不同类型的手势,但他不知道哪一种代表“蹄”,哪一种代表“纸”,哪一种代表“剪刀”(在农夫约翰未经训练的眼里,它们似乎都是“蹄”的变体……)

由于不知道这三个手势的意思,农夫约翰给他们分配了数字1、2和3。可能手势1代表“蹄子”,也可能代表“纸”;他的意思不清楚。考虑到两头母牛在所有N场比赛中做出的手势,请帮助农夫约翰确定第一头母牛可能赢得的最大游戏数,给出数字和它们各自手势之间的适当映射。

输入格式(Format Input)

The first line of the input file contains N.
Each of the remaining N lines contain two integers (each 1, 2, or 3), describing a game from Farmer John’s perspective.
输入文件的第一行包含N。
剩下的N行中的每一行都包含两个整数(分别为1、2或3),从农夫约翰的角度描述了一场游戏。
输出格式(Format Output)
Print the maximum number of games the first of the two cows could possibly have won.
打印两头母牛中第一头可能赢得的最大游戏数。

输入样例(Sample Input)


5
1 2
2 2
1 3
1 1
3 2

输出样例(Sample Output)


2

说明/提示(Hint)


One solution (of several) for this sample case is to have 1 represent “scissors”, 2 represent “hoof”, and 3 represent “paper”. This assignment gives 2 victories to the first cow (“1 3” and “3 2”). No other assignment leads to more victories.
对于这个示例案例,一种解决方案是1代表“剪刀”,2代表“蹄子”,3代表“纸”。这项任务给第一头牛两次胜利(“1 3”和“3 2”)。没有其他任务能带来更多的胜利。

#include<bits/stdc++.h>
using namespace std;
int n,ans1,ans2;
int fir[1001],sec[1001];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>fir[i]>>sec[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(fir[i]-sec[i]==-1||fir[i]-sec[i]==2)
        {
            ans1++;
        }
        if(fir[i]-sec[i]==1||fir[i]-sec[i]==-2)
        {
            ans2++;
        }
    }
    cout<<max(ans1,ans2);
    return 0;
}

给六年级朋友的忠告

有些所谓的友情,在功利面前都是Plastic。

真正懂你、理解你,甚至是爱你的朋友很少,请坚信:友不必多。

在六年级,只要你越疯狂,并且到很多人“喜欢”的程度,就越受欢迎(比如我们班最近就有人搞啥“生化武器”)。所以请保持自己的节操。

总结

你的友情只值得一小部分人

保持自己的高尚品质

谢谢!