#include<bits/stdc++.h>#define int long long#define endl '\n'using namespace std;
int s[205][205];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s = "",a;
while(cin>>a) s += a;
cout<<sqrt(s.size())<<" ";
if(s[0] == '1')
{
cout<<"0 ";
}
int dp = 1;
for(int i = 1;i<s.size();i++)
{
if(s[i] == s[i-1]) dp++;
else
{
cout<<dp<<" ";
dp = 1;
}
}
cout<<dp;
return 0;
}
4.错误原因:想复杂的了
T831483
1.题意:小 C 和方格是好朋友。小 C 有一个 n 行 m 列的方格图,每个方格中都有一个数字,其中第 i 行第 j 列的方格中的数字为 a i j。我们定义,在这个方格图中,两个不同的方格不相邻,当且仅当这两个方格没有公共边。小 C 认为,两个不同的方格互为好朋友,当且仅当这两个方格不相邻且这两个方格中的数字相同。小 C 想让你帮忙求出,所有方格的好朋友的数量之和是多少。
#include<bits/stdc++.h>#define int long long#define endl '\n'using namespace std;
int a[2005][2005],n,m,tong[200005];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=m;j++)
{
cin>>a[i][j];
tong[a[i][j]]++;
}
}
int cnt = 0;
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=m;j++)
{
int s = (tong[a[i][j]]-1);
if(a[i][j] == a[i+1][j]) s--;
if(a[i][j] == a[i][j+1]) s--;
if(a[i][j] == a[i-1][j]) s--;
if(a[i][j] == a[i][j-1]) s--;
cnt += s;
}
}
cout<<cnt;
return 0;
}
4.错误原因:忘记定义s变量了。
T831483
1.题意:小 C 和方格是好朋友。小 C 有一个 n 行 m 列的方格图,每个方格中都有一个数字,其中第 i 行第 j 列的方格中的数字为 a i j。我们定义,在这个方格图中,两个不同的方格不相邻,当且仅当这两个方格没有公共边。小 C 认为,两个不同的方格互为好朋友,当且仅当这两个方格不相邻且这两个方格中的数字相同。小 C 想让你帮忙求出,所有方格的好朋友的数量之和是多少。