IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> AtCoder Beginner Contest 042(Virtual Participation) -> 正文阅读

[C++知识库]AtCoder Beginner Contest 042(Virtual Participation)

本菜鸟的情况:?


A - Iroha and Haiku (ABC Edition)?

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 100?points

Problem Statement

Iroha loves?Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with?5,?7?and?5?syllables, in this order.

To create a Haiku, Iroha has come up with three different phrases. These phrases have?A,?B?and?C?syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Constraints

  • 1≦A,B,C≦10

Input

The input is given from Standard Input in the following format:

A B C

Output

If it is possible to construct a Haiku by using each of the phrases once, print?YES?(case-sensitive). Otherwise, print?NO.


Sample Input 1

5 5 7

Sample Output 1

YES

Using three phrases of length?5,?5?and?7, it is possible to construct a Haiku.


Sample Input 2

7 7 5

Sample Output 2

NO

?解题思路:

? ? ? ? 这个题还是非常简单的,实际上就是要去判断输入的三个数是不是5,5,7(顺序无所谓),是的话则输出YES,否则的话输出NO。简单来说直接拿个数组,排序之后判断就可以了。

AC代码:

#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e6;

ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll qpow(ll a,ll b)
{
	ll f=1;
	while (b)
	{
		if (b&1)
			f=f*a;
		a=a*a;
		b>>=1;
	}
	return f;
}

void solve()
{
	int a[3];
	for (int i=0;i<3;i++)
		cin>>a[i];
	sort(a,a+3);
	if (a[0]!=5||a[1]!=5||a[2]!=7)
		cout<<"NO";
	else
		cout<<"YES";
}

int main()
{
	solve();
	return 0;
}

B - Iroha Loves Strings (ABC Edition)

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 200?points

Problem Statement

Iroha has a sequence of?N?strings?S1?,S2?,...,SN?. The length of each string is?L.

She will concatenate all of the strings in some order, to produce a long string.

Among all strings that she can produce in this way, find the lexicographically smallest one.

Here, a string s=s1?s2?s3?...sn??is?lexicographically smaller?than another string t=t1?t2?t3?...tm??if and only if one of the following holds:

  • There exists an index?i(1≦i≦min(n,m)), such that sj?=tj??for all indices?j(1≦j<i), and si?<ti?.
  • si?=ti??for all integers?i(1≦i≦min(n,m)), and?n<m.

Constraints

  • 1 ≦ N, L ≦ 100
  • For each?i, the length of Si??equals?L.
  • For each?i, Si??consists of lowercase letters.

Input

The input is given from Standard Input in the following format:

N L
S1?
S2?
:
SN?

Output

Print the lexicographically smallest string that Iroha can produce.


Sample Input 1

3 3
dxx
axx
cxx

Sample Output 1

axxcxxdxx

The following order should be used:?axx,?cxx,?dxx.


?

解题思路:

? ? ? ? 别问我为啥错了这么多次,把拼接字符串的个数写成了L,害的我找了半天才找出来。这个题其实只需要用一个string数组,进行排序后一个一个拼接在后面就可以了。

AC代码:

#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e6;

ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll qpow(ll a,ll b)
{
	ll f=1;
	while (b)
	{
		if (b&1)
			f=f*a;
		a=a*a;
		b>>=1;
	}
	return f;
}

void solve()
{
	int n,l;
	cin>>n>>l;
	string s[105];
	for (int i=0;i<n;i++)
		cin>>s[i];
	sort(s,s+n);
	string t="";
	for (int i=0;i<n;i++)
		t+=s[i];
	cout<<t;
}

int main()
{
	solve();
	return 0;
}

C - Iroha's Obsession

Time Limit: 2 sec / Memory Limit: 256 MB

Score :?300?points

Problem Statement

Iroha is very particular about numbers. There are?K?digits that she dislikes: D1?,D2?,...,DK?.

She is shopping, and now paying at the cashier. Her total is?N?yen (the currency of Japan), thus she has to hand at least?N?yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

  • 1 ≦ N < 10000
  • 1 ≦ K < 10
  • 0≦D1?<D2?<…<DK?≦9
  • {D1,D2,...,DK} ≠ {1,2,3,4,5,6,7,8,9}

Input

The input is given from Standard Input in the following format:

N K
D1? D2? … DK?

Output

Print the amount of money that Iroha will hand to the cashier.


Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output?

2000

She dislikes all digits except?0?and?2.

The smallest integer equal to or greater than N=1000?whose decimal notation contains only?0?and?2, is?2000.


Sample Input 2

9999 1
0

Sample Output 2

9999

解题思路:

? ? ? ? 这个题我一开始想得太复杂了,后来才反应过来直接暴力解就可以。先把D数组中出现的数标记一下,之后一位一位的进行比较,看看每一位的数字是否都不在D中出现。直到出现正确答案为止。

AC代码:

#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e6;

ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll qpow(ll a,ll b)
{
	ll f=1;
	while (b)
	{
		if (b&1)
			f=f*a;
		a=a*a;
		b>>=1;
	}
	return f;
}

void solve()
{
	int n,k;
	cin>>n>>k;
	int a[10],b[10];
	memset(b,0,sizeof(b));
	for (int i=0;i<k;i++)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	while (true)
	{
		int x=n;
		int f=0;
		while (x)
		{
			int y=x%10;
			x/=10;
			if (b[y])
			{
				f=1;
				break;
			}
		}
		if (!f)
		{
			cout<<n;
			break;
		}
		n++;
	}
}

int main()
{
	solve();
	return 0;
}

D - Iroha and a Grid

Time Limit: 2 sec / Memory Limit: 256 MB

Score :?400?points

Problem Statement

We have a large square grid with?H?rows and?W?columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.

However, she cannot enter the cells in the intersection of the bottom?A?rows and the leftmost?B?columns. (That is, there are A×B?forbidden cells.) There is no restriction on entering the other cells.

Find the number of ways she can travel to the bottom-right cell.

Since this number can be extremely large, print the number modulo?10^{9}+7.

Constraints

  • 1 ≦ H, W ≦ 100,000
  • 1≦A<H
  • 1 ≦ B < W

Input

The input is given from Standard Input in the following format:

H W A B

Output

Print the number of ways she can travel to the bottom-right cell, modulo?10^{9}+7.


Sample Input 1

2 3 1 1

Sample Output 1

2

We have a?2×3?grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".


Sample Input 2

10 7 3 4

Sample Output 2

3570

There are?12?forbidden cells.


Sample Input 3

100000 100000 99999 99999

Sample Output 3

1

Sample Input 4

100000 100000 44444 55555

Sample Output 4

738162020

解题思路:

? ? ? ? 这个题在一开始没有做出来。开始的思想很简单,想着用dp直接做,但是都失败了,因为这个二维数组开得太大,结束之后看题解才发现了一个类似于杨辉三角的模型,正解应该是拿类似于排列组合的思想。这个就涉及到组合数学中的常用算法,此处应用的是组合问题(有关组合数学的相关知识点),即C_{n}^{m}的计算,套路是很固定的,直接套模板即可。

? ? ? ??方案数的求解

AC代码:

#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
const int N=1e5+5;
ll fnv[2*N],fac[2*N]={1};

ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll qpowmod(ll a,ll b)
{
	ll f=1%mod;
	while (b)
	{
		if (b&1)
			f=f*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return f;
}

void pre()
{
	for (int i=1;i<=2*N;i++)
		fac[i]=fac[i-1]*i%mod;
	fnv[0]=1;
	fnv[2*N]=qpowmod(fac[2*N],mod-2);
	for (int i=2*N-1;i>=1;i--)
		fnv[i]=fnv[i+1]*(i+1)%mod;
}

ll C(int m,int n)
{
	return fac[m]*fnv[n]%mod*fnv[m-n]%mod;
}
//注释掉的部分是一个错误的代码,也是在做题的时候第一时间想到的思路代码
//ll dp[99999][99999];
//void solve()
//{
//	int h,w,a,b;
//	cin>>h>>w>>a>>b;
//	for (int i=1;i<=h;i++)
//		dp[i][1]=1;
//	for (int i=1;i<=w;i++)
//		dp[1][i]=1;
//	for (int i=h;i>=h-a+1;i--)
//	{
//		for (int j=1;j<=b;j++)
//			dp[i][j]=0;
//	}
//	for (int i=2;i<=h;i++)
//	{
//		for (int j=2;j<=w;j++)
//		{
//			if (i<=h-a||j>b)
//				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
//		}
//	}
//	cout<<dp[h][w];
//}
void solve()
{
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	pre();
	ll ans=0;
	for (int i=b+1;i<=w;i++)
		ans=(ans+C(h-a+i-2,i-1)*C(a+w-i-1,a-1)%mod)%mod;
	cout<<ans;
}

int main()
{
	solve();
	return 0;
}

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-02-22 20:23:18  更:2022-02-22 20:24:26 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 6:19:43-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码