日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【模拟】Ingenious Lottery Tickets

發布時間:2025/3/8 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【模拟】Ingenious Lottery Tickets 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

Your friend Superstitious Stanley is always getting himself into trouble. This time, in his Super Lotto Pick?and Choose plan, he wants to get rich quick by choosing the right numbers to win the lottery. In this?lottery, entries consist of six distinct integers from 1 to 49, which are written in increasing order. Stanley has?compiled a list of winning entries from the last n days, and is going to use it to pick his winning numbers.?
In particular, Stanley will choose the six numbers that appeared the most often. When Stanley is breaking?ties, he prefers smaller numbers, except that he prefers seven to every other number. What is Stanley’s?entry?

?

輸入

The first line of input contains a single integer T (1 ≤ T ≤ 100), the number of test cases. The first line?of each test case contains a single integer n (1 ≤ n ≤ 1,000), the number of winning entries that Stanley?compiled. The next n lines each contain a lottery entry as described above.

?

輸出

For each test case, output a single line containing Stanley’s entry.

?

樣例輸入

復制樣例數據

2 3 1 2 3 4 5 6 4 5 6 7 8 9 7 8 9 10 11 12 3 1 2 3 4 5 6 4 5 6 7 8 9 1 2 3 7 8 9

樣例輸出

4 5 6 7 8 9 1 2 3 4 5 7

?

提示

In the first test case, the numbers 4 through 9 appear twice each, while all other numbers appear at most
one time.
In the second test case, all numbers 1 through 9 appear twice each. The tiebreaking rule means Stanley
prioritizes picking 7 and then the five smallest numbers.

?

題目大意:

先輸入一個整數t,代表下面有t組測試,對于每一組測試,先輸入一個整數n,下面n行每行輸入六個0到49的整數,計算每個整數出現的次數,找到出現次數最多的6個整數,按從小到大的順序輸出,且若7出現的次數與其他數字出現的次數相同,優先考慮7.

解題思路:

記錄一下每一個數字出現的次數,將其存到一個結構體中,然后按照出現次數的大小對結構體進行排序,先將前5位存起來,若7已被存起,則繼續存入第六位,若7沒被存入,則比較7出現的次數與第六個元素出現的次數的大小,如果相等,則存入7,否則存入第六項。

代碼:

#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #include <sstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)1e5 + 5; const ll mod = 1e9+7; struct node {int x;int num; }arr[1200]; map<int,int> ma; bool cmp(node a,node b) {if(a.num==b.num) return a.x<b.x;return a.num>b.num; } int arr1[10]; int main() {#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int t;cin>>t;while(t--) {int n;cin>>n;int nape,num7=0;ma.clear();int cnt=0;rep(i,1,n) {rep(j,1,6) {cin>>nape;if(nape==7) num7++;if(ma[nape]!=0) arr[ma[nape]].num++;else {cnt++;ma[nape]=cnt;arr[ma[nape]].x=nape;arr[ma[nape]].num=1;}}}sort(arr+1,arr+1+cnt,cmp);bool ju=false;rep(i,1,5) {arr1[i]=arr[i].x;if(arr[i].x==7) ju=true;}if(ju==false) {if(num7==arr[6].num) arr1[6]=7;else arr1[6]=arr[6].x;}else arr1[6]=arr[6].x;sort(arr1+1,arr1+7);rep(i,1,6) cout<<arr1[i]<<" ";cout<<endl;}return 0; }

?

總結

以上是生活随笔為你收集整理的【模拟】Ingenious Lottery Tickets的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。