题目大意:如果字符串末尾的字符数‘)’严格大于剩余字符数,则消息是错误的。
【字符串s末尾的)要严格大于剩下的则为Yes,否则为No 】
input
5 2 )) 12 gl))hf)))))) 9 gege))))) 14 )aa))b)))))))) 1 )output
Yes No Yes Yes Yes
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
//cin.tie(0);
//ios::sync_with_stdio(false);
int t; cin>>t;
while(t--)
{
int n; cin>>n;
string s; cin>>s;
int sum=0;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]==')')sum++;
else break;
}
//cout<<sum<<endl;
if(sum>n-sum) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
题目大意:如果一个正整数可以被它的每个非零位整除,我们称它为公平的。例如,102是公平的(因为它可以被1和2整除),但第282不是,因为它不能被8整除。给定一个正整数n,找出最小整数x,使n≤x和x是公平的。
一个正整数可以被它的每个非零位整除(1和0直接排除,用暴力循环做)
input
4 1 282 1234567890 1000000000000000000output
1 288 1234568040 1000000000000000000
注意事项。
部分测试用例说明:
在第一个测试案例中,1号本身是公平的。
在第二个测试用例中,编号288是公平的(它可以被2和8整除)。[282,287]中没有一个数字是公平的,因为,例如,它们都不能被8整除。
/*知识点
函数原型:
string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);
功能:
将数值转化为字符串。返回对应的字符串
eg:
#include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int t; cin>>t;
while(t--)
{
long long int n; cin>>n;
string s=to_string(n);
cout<<s<<endl;
}
return 0;
}*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int t; cin>>t;
while(t--)
{
long long int n; cin>>n;
while(1)
{
int flag=0;
string s=to_string(n);
for(int i=0;i<s.length();i++)
{
if(s[i]=='0'||s[i]=='1') continue;
else if(n%(s[i]-'0')!=0) { flag=1; break; }
}
if(flag==1) n++;
else break;
}
cout<<n<<endl;
}
return 0;
}
题目大意:一个n×n的棋盘。黑板的行号和列号从1到n。单元格(x,y)位于列号x和行号y的交点上。一个棋子,可以在一个回合中垂直或水平移动任意数量的单元格。(即不存在共享一行或一列的一对车。)在一个回合中,你可以将一辆车垂直或水平移动任意数量的单元格。另外,它在移动后不应该被任何其他车攻击。把所有的车挂在主对角线上所需的最少移动次数是多少?(保证在最初的位置不会有两个菜鸟互相攻击。)【将所有的点(不在同一行同一列)都跳到对角线上去,求最小的步数 】
input
4 3 1 2 3 3 2 2 1 1 2 5 3 2 3 3 1 1 2 5 4 4 5 5 1 2 2 3 3output
1 3 4 2
/*
知识点
acwing朴素并查集:
int p[N]; //存储每个点的祖宗节点
int find(int x)//返回x的祖宗节点
{
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
}
for(int i=1;i<=n;i++) p[i]=i;//初始化,假定节点编号是1~n
p[find(a)] = find(b);//合并a和b所在的两个集合
*/
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
using namespace std;
const int maxn=1e6+10;
using namespace std;
int p[maxn];
int find(int x)
{
if(x!=p[x]) p[x]=find(p[x]);
return p[x];
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int t; cin>>t;
while(t--)
{
int n,m; cin>>n>>m;
for(int i=1;i<=n;i++) p[i]=i;//并查集模板初始化条件
int cnt=0,ans=0;
while(m--)
{
int x,y; cin>>x>>y;
if(x==y) continue;//当x和y相等时,已经在对角线上了,直接跳过不用合并
if(find(x)!=find(y)) p[find(x)]=find(y);//当两者的祖先都不一样的时候,合并x和y的两个集合
else cnt++;//当形成了环的时候就直接加一个
ans++;//ans==m就是点数
}
cout<<ans+cnt<<endl;
}
return 0;
}