7-1 Fake News

该博客介绍了一种用于识别假新闻的算法,通过比较多个新闻网站对同一重要事件的报道,计算每个网站报告假新闻的可能性。算法首先选择N个新闻站点,然后对每个事件,计算每个站点与其他站点意见不同的比例,找出最可能发布假新闻的站点,并记录其频率。最终,找到最常被标记为发布假新闻的站点。输入和输出规格也详细说明了算法的运行方式。
摘要由CSDN通过智能技术生成

No news site is unbiased, but some do a better job of trying to balance facts and opinions. The term fake news means "news articles that are intentionally and verifiably false" designed to manipulate people's perceptions of real facts, events, and statements. (Quoted from https://www.cits.ucsb.edu/fake-news/what-is-fake-news)

To tell if a news media is more or less likely to be fake, you can keep an eye on several different sites to see how they report on the same important events. The algorithm works as the following:

  • Select N news sites.
  • For each important event, scan every site and represent each different opinion by a distinct integer.
  • Define the likelihood of a site i being fake news by Fi​=ni​/N, where ni​ is the number of sites that have different opinions than site i.
  • Find the news site(s) which is(are) the most likely to report fake news.
  • For each news site, count the number of times it was the most likely to be fake, and find the one that is in most of the cases the most likely to be fake.

Input Specification:

Each input file contains one test case. For each case, the first line contains two positive numbers: N (≤104) which is the number of news sites, and M (≤100) which is the number of events. Then M lines follow, each describes the reports of the sites in the format:

R1​ R2​ ... RN​

where Ri​ is an integer in the range [−104,104], and reprensts the opinion of site i.

Output Specification:

For each test case, print in a line the index of the site which is in most of the cases the most likely to be fake. The answer is guaranteed to be unique.

Sample Input:

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

Sample Output:

4

Event 1: 3/4 3/4 2/4 2/4 --> 1 and 2 are the most likely
Event 2: 1/4 1/4 1/4 3/4 --> 4 is the most likely
Event 3: 3/4 2/4 2/4 3/4 --> 1 and 4 are the most likely
Event 4: 0 0 0 0 --> all are the most likely
Event 5: 2/4 2/4 2/4 2/4 --> all are the most likely
Event 6: 2/4 2/4 3/4 3/4 --> 3 and 4 are the most likely
 

#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;
const int N = 10010;
int r[N];
int n,m,most_fake;
unordered_map<int,int> fake_cnt;
int main(){
    cin>>n>>m;
    while(m--){
        vector<int> may_fake;
        unordered_map<int,int> cnt;
        for(int i = 1;i<=n;i++) {
            cin>>r[i];
            cnt[r[i]]++;
        }
        double fake_p = -1;
        for(int i = 1;i<=n;i++){
           double p = (n-cnt[r[i]])*1.0/n;
           if(p>fake_p){
               may_fake.clear();
               fake_p = p;
               may_fake.push_back(i);
           }else if(p==fake_p){
               may_fake.push_back(i);
           }
        }
        for(auto t:may_fake){
            fake_cnt[t]++;
        }
    }
    int res = 0;
    for(auto t:fake_cnt){
        int id = t.first;
        int cnt = t.second;
        if(cnt>res){
            res = cnt;
            most_fake = id;
        }
    }
    cout<<most_fake<<endl;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值