记两个水题

来源:互联网 发布:恢复数据 英语 编辑:程序博客网 时间:2024/05/20 01:36

B - Line Fighting
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice URAL 2025

Description

Boxing, karate, sambo… The audience is sick of classic combat sports. That is why a popular sports channel launches a new competition format based on the traditional Russian entertainment called line fighting. There can be from 2 to k teams taking part in a competition, and there are n fighters altogether in all the teams. Before the competition starts, the fighters are divided into teams: each fighter becomes a member of exactly one team. Two fighters fight each other if they are members of different teams. The organizers believe that the more the number of fights between fighters, the higher the popularity of a competition will be. Help the organizers to distribute fighters between teams so as to maximize the number of fights and output this number.

Input

The first line contains the number of tests T (1 ≤ T ≤ 10). In each of the following T lines you are given a test: integers n and k separated with a space (2 ≤ k ≤ n ≤ 10 4).

Output

For each test output the answer (one integer) in a separate line.

Sample Input

inputoutput
36 35 54 2
12104

有n个人 要分成2-k个队  每两个队中的人互相打比赛  现在要将这些人分组使得比赛场数最多

思路:

就是把n个人分到k个组 尽量平均分配  然后计算  我是根据公示计算的

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#define eps 1e-8#define op operator#define MOD  10009#define MAXN  100100#define INF 0x7fffffff#define MEM(a,x)    memset(a,x,sizeof a)//#define ll __int64using namespace std;int a[10010];int main(){//freopen("ceshi.txt","r",stdin);    int tc;    scanf("%d",&tc);    while(tc--)    {        int n,k;        scanf("%d%d",&n,&k);        for(int i=0;i<k;i++)        {            a[i]=n/k;        }        int b=n%k;        int cnt=0;        while(b)        {            a[cnt++]++;            b--;        }//        cout<<"cnt  "<<cnt<<endl;        int sum=0;        if(cnt==0)        {            sum=a[0]*a[0]*(k*(k-1)/2);            printf("%d\n",sum);            continue;        }        if(cnt==1)        {            sum+=a[0]*a[1]*(k-1);//            sum+=a[0]*a[k-1]*cnt*(k-cnt);            sum+=a[1]*a[1]*((k-1)*(k-2)/2);            printf("%d\n",sum);            continue;        }        if(cnt>1&&cnt<(k-1))        {            sum+=a[0]*a[0]*(cnt*(cnt-1)/2);            sum+=a[0]*a[k-1]*cnt*(k-cnt);            sum+=a[k-1]*a[k-1]*((k-cnt)*(k-cnt-1)/2);            printf("%d\n",sum);            continue;        }        if(cnt==(k-1))        {            sum+=a[0]*a[0]*(cnt*(cnt-1)/2);            sum+=a[0]*a[k-1]*(k-1);            printf("%d\n",sum);            continue;        }    }    return 0;}

J - Devices
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice URAL 2033

Description

Students of the Department of Mathematics and Mechanics enjoy buying modern devices. Not having much money, they buy new devices rarely but expertly. They trust their friends’ opinion and choose a device of the type that the greatest number of their friends have. If there are several such devices, the students choose the cheapest of them. Student Ilya is no exception. He has questioned his six friends and now wants to choose a new device according to the above rule. Note that the friends could buy the same device in different places at different prices, and Ilya can buy this device at the smallest price.

Input

The input contains descriptions of devices of six friends. Each description is in three lines. You are given the name of a friend in the first line, the name of this friend’s device in the second line, and the price of the device in the third line.
All the words are strings of size from 1 to 20 characters. The friends’ names contain only lowercase English letters, and the names of the devices consist of lowercase English letters and digits. The price is an integer from 1 to 10 6. The names of the friends may coincide.

Output

In the only line output the name of the device in possession of the greatest number of friends. If there are several such devices, output the name of the cheapest of them. If there are again several such devices, output the name of any of them.

Sample Input

inputoutput
olegnexus413000kirillkurtka20000dennexus412000nikitahtc10000mikhailnexus414000alexeyhtc9500
nexus4

有人想要买手机   根据他的6个朋友买手机的情况选择手机  

首先选择手机牌子买的个数最多的  假如有好几个一样的 再选择价格最低的

同一个牌子的手机 可能会出现不同的价格  也选择价格最低的

map的简单应用

之前使用getline 不对

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <map>#define eps 1e-8#define op operator#define MOD  10009#define MAXN  100100#define INF 0x7fffffff#define MEM(a,x)    memset(a,x,sizeof a)//#define ll __int64using namespace std;map<string,int> m1;//记录手机的数量map<string,int> m2;//记录手机价格int main(){//freopen("ceshi.txt","r",stdin);    string s1,s2;    int c;    string s[10];    for(int i=0;i<6;i++)    {//        getline(cin,s1);//        getline(cin,s2);        cin>>s1; cin>>s2;        scanf("%d",&c);//        getchar();        m1[s2]++;        if(m1[s2]>1)        {            if(m2[s2]>c)                m2[s2]=c;        }        else m2[s2]=c;        s[i]=s2;    }    int num=-1;    int pr=(int)1e6;    string ans;    for(int i=0;i<6;i++)    {        if(num<m1[s[i]])        {            num=m1[s[i]];            pr=m2[s[i]];            ans=s[i];        }        else        {            if(num==m1[s[i]]&&pr>m2[s[i]])            {                pr=m2[s[i]];                ans=s[i];            }        }    }    cout<<ans<<endl;    return 0;}




0 0
原创粉丝点击