11.18
B. Valerii Against Everyone
题目:其实就是找有没有相同的数字
思路:但是用简单的数组进行去重会超时,所以要用map去重,map如果没有这个值会默认是0,所以也用for循环进行查找是否map数组中含有这个数
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<set> 7 #include<queue> 8 #include<map> 9 using namespace std; 10 const int maxx=1e5+10;//31 11 //用map进行去重一定记得这个方法,用简单数组去重会超时 12 int main(){ 13 int n; 14 map<int,int> mp; 15 scanf("%d",&n); 16 while(n--){ 17 int m; 18 mp.clear(); 19 scanf("%d",&m); 20 int flag=0; 21 for(int i=0;i<m;i++){ 22 int nn; 23 scanf("%d",&nn); 24 if(mp[nn]==0){ 25 mp[nn]=1; 26 }else{ 27 flag=1; 28 } 29 } 30 if(flag==0){ 31 printf("NO\n"); 32 }else{ 33 printf("YES\n"); 34 } 35 } 36 }
PTA.7-47
题目:整出光棍
思路:大整数模拟除法:截取一个个小段的数--->如果数可以除开商,其中还要输出为0的情况--->变换这一小段数,为余数*10+后面的数--->(因为此处是在找最小的,所以只要一能整除尽就退出)
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<set> 7 #include<queue> 8 #include<map> 9 using namespace std; 10 const int maxx=1e5+10;//34 11 int main(){ 12 int x=0; 13 int n,ff=0;//防止打印前导0 14 scanf("%d",&n); 15 int num=0;//记录位数 16 while(1){ 17 //截取一个个小段的数->如果数可以除开商,输出->输出为0的情况-> 18 //->变换这一小段数,为余数*10+后面的数->(因为此处是在找最小的,所以只要一能整除尽就退出) 19 x=x*10+1; 20 num++; 21 if(x>=n){ 22 ff=1; 23 printf("%d",x/n); 24 }else if(ff==1){ 25 printf("0"); 26 } 27 x=x%n; 28 if(x==0){ 29 break; 30 } 31 } 32 printf(" %d\n",num); 33 34 }

浙公网安备 33010602011771号