ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2020-2-6赛

2020-02-06 18:09:32  阅读:328  来源: 互联网

标签:blocks int sum cat 2020 words each


理解题意很重要,思维好题,spj:答案多个,任意个就判对

问题 B: 求和
时间限制: 1 Sec  内存限制: 128 MB  Special Judge
[提交] [状态] 
题目描述 
考虑自然数1到N,在这N个数之前添加“+”或“-”,然后将N数相加得到和S(0 < S≤100000)。求可以获得和S最小的自然数N。 
输入 
仅包含1行,一个整数,表示和S。 
输出 
第1行一个正整数,表示获得和S的最小自然数N。
接下来若干行,每行一个整数,表示添加了“-”的自然数(添加了“+”的自然数不输出),按从小到大的顺序输出。注意:添加“+”或“-”的方案可能不唯一。

样例输入 Copy 
12
样例输出 Copy 
7
1
7
提示 
因为12=-1+2+3+4+5+6-7,故获得和12的最小自然数是7,在1到7的7个自然数中,在1和7之前添加了“-”。

10%的数据保证0 < S≤ 20
30%的数据保证0 < S≤ 150
60%的数据保证0 < S≤ 50000
100%的数据保证0 < S≤ 100000
 

 

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,sum=0;
  scanf("%d",&n);
  for(int i=1;;i++)
  {
      sum+=i;
      if(sum==n)
      {
          printf("%d",i); return 0;
      }
      if(sum>n&&(sum-n)%2==0)//+1和-1差2
      {
         printf("%d\n",i);
         break;
      }
  }
  if((sum-n)/2==1)
  {
      printf("1\n");
  }
  else if((sum-n)/2!=1)
  {
      if((sum-n)/2==2) printf("2\n");
      else
      {
           printf("1\n");
           printf("%d\n",(sum-n)/2-1);
      }

  }


    return 0;
}

 

问题 N: Block Game 
时间限制: 1 Sec  内存限制: 128 MB
[提交] [状态] 
题目描述 
Farmer John is trying to teach his cows to read by giving them a set of N spelling boards typically used with preschoolers (1≤N≤100). Each board has a word and an image on each side. For example, one side might have the word 'cat' along with a picture of a cat, and the other side might have the word 'dog' along with a picture of a dog. When the boards are lying on the ground, N words are therefore shown. By flipping over some of the boards, a different set of N words can be exposed. 
To help the cows with their spelling, Farmer John wants to fashion a number of wooden blocks, each embossed with a single letter of the alphabet. He wants to make sufficiently many blocks of each letter so that no matter which set of Nwords is exposed on the upward-facing boards, the cows will be able to spell all of these words using the blocks. For example, if N=3 and the words 'box', 'cat', and 'car' were facing upward, the cows would need at least one 'b' block, one 'o' block, one 'x' block, two 'c' blocks, two 'a' blocks, one 't' block, and one 'r' block. 
Please help the Farmer John determine the minimum number of blocks for each letter of the alphabet that he needs to provide, so that irrespective of which face of each board is showing, the cows can spell all N visible words. 
输入 
Line 1 contains the integer N. 
The next N lines each contain 2 words separated by a space, giving the two words on opposite sides of a board. Each word is a string of at most 10 lowercase letters. 
输出 
Please output 26 lines. The first output line should contain a number specifying the number of copies of 'a' blocks needed. The next line should specify the number of 'b' blocks needed, and so on. 
样例输入 Copy 
3
fox box
dog cat
car bus
样例输出 Copy 
2
2
2
1
0
1
1
0
0
0
0
0
0
0
2
0
0
1
1
1
1
0
0
1
0
0
提示 
In this example, there are N=3 boards, giving 23=8 possibilities for the set of upward-facing words: 
fox dog car 
fox dog bus 
fox cat car 
fox cat bus 
box dog car 
box dog bus 
box cat car 
box cat bus 
We need enough blocks for each letter of the alphabet so that we can spell all three words, irrespective of which of these eight scenarios occurs. 

 

开始以为这道题是二叉树,,虽然我根本没学过,,但是这个其实是简化版的排列组合啊。。。。只用考虑我每次是加1号的字母数还是2号的。。。。水题。。。

#include<bits/stdc++.h>
using namespace std;
char st1[105],st2[105];
 int a[27]={0},b[27]={0};
int A[27];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
      scanf("%s %s",st1,st2);
      int len1=strlen(st1);
      int len2=strlen(st2);
      for(int j=0;;j++)
      {
          if(j>=max(len1,len2))
            break;
          if(j<len1) a[st1[j]-'a']++;
          if(j<len2) b[st2[j]-'a']++;
      }
      for(int j=0;j<27;j++)
        {
            A[j]+=max(a[j],b[j]);
            a[j]=0;b[j]=0;
        }
    }
  for(int i=0;i<26;i++)
   {
      printf("%d",A[i]);
      if(i!=25) printf("\n");

   }

    return 0;
}

 

QXK_Jack 发布了17 篇原创文章 · 获赞 1 · 访问量 395 私信 关注

标签:blocks,int,sum,cat,2020,words,each
来源: https://blog.csdn.net/QXK_Jack/article/details/104199643

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有